Skip to content

Commit

Permalink
Merge pull request #396 from MTES-MCT/jacoco
Browse files Browse the repository at this point in the history
feat(backend): add jacoco test coverage report
  • Loading branch information
lwih authored Oct 30, 2024
2 parents 3eba579 + 2c4be74 commit b2e1240
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
19 changes: 15 additions & 4 deletions .github/workflows/build-and-test-backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,20 @@ jobs:
- name: Install and Build Backend
uses: ./.github/actions/install-and-build-backend

- name: "Tests & Coverage"
env:
CI: true
run: make back-test-coverage

- name: Add coverage to PR
id: jacoco
uses: madrapps/[email protected]
with:
paths: |
${{ github.workspace }}/**/backend/build/reports/jacoco/**/jacocoTestReport.xml
token: ${{ secrets.GITHUB_TOKEN }}


# - name: dependency-check
# uses: dependency-check/Dependency-Check_Action@main
# id: dependency-check
Expand All @@ -46,10 +60,7 @@ jobs:
# - name: "Analyse dependencies"
# run: make back-check-dependencies

# - name: "Tests"
# env:
# CI: true
# run: make back-test


# - name: "Check clean architecture"
# run: make check-clean-archi
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ back-build:
back-test:
cd $(BACKEND_DIR) && ./gradlew test

back-test-coverage:
cd $(BACKEND_DIR) && ./gradlew test jacocoTestReport

back-start-local:
cd $(BACKEND_DIR) && ./gradlew bootRun --args='--spring.profiles.active=local --spring.config.additional-location=$(BACKEND_CONFIGURATION_FOLDER)'

Expand Down
19 changes: 19 additions & 0 deletions backend/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ plugins {
id("io.spring.dependency-management") version "1.1.4"
id("org.owasp.dependencycheck") version "8.4.0"
id("org.flywaydb.flyway") version "10.10.0"
jacoco
}

springBoot {
Expand Down Expand Up @@ -149,3 +150,21 @@ tasks.register<Copy>("getDependencies") {
File("runtime").deleteRecursively()
}
}

jacoco {
toolVersion = "0.8.12"
reportsDirectory = layout.buildDirectory.dir("reports/jacoco")
}

tasks.jacocoTestReport {
reports {
xml.required.set(true) // Enable XML report (for CI integration)
html.required.set(true) // Enable HTML report
html.outputLocation = layout.buildDirectory.dir("jacocoHtml")
}
}

tasks.test {
useJUnitPlatform() // If you are using JUnit 5
finalizedBy(tasks.jacocoTestReport) // Generate the report after tests
}

0 comments on commit b2e1240

Please sign in to comment.