Skip to content

Commit 1e81f6c

Browse files
committed
tests: reworks deps using more modern jvm-test-suite ands new full coverage reports.
1 parent 7a3089a commit 1e81f6c

File tree

7 files changed

+90
-84
lines changed

7 files changed

+90
-84
lines changed

auth-service/auth-service-web/auth-web-lib/build.gradle.kts

-60
Original file line numberDiff line numberDiff line change
@@ -15,64 +15,4 @@ dependencies {
1515
implementation("org.springframework.security:spring-security-oauth2-authorization-server")
1616
implementation("org.springframework.security:spring-security-cas")
1717
implementation("org.springframework:spring-jdbc")
18-
}
19-
20-
sourceSets {
21-
create("integrationTest") {
22-
compileClasspath += sourceSets.main.get().output
23-
runtimeClasspath += sourceSets.main.get().output
24-
}
25-
}
26-
27-
val integrationTestImplementation by configurations.getting {
28-
extendsFrom(configurations.implementation.get())
29-
}
30-
val integrationTestRuntimeOnly by configurations.getting
31-
32-
configurations["integrationTestRuntimeOnly"].extendsFrom(configurations.runtimeOnly.get())
33-
34-
val integrationTest = task<Test>("integrationTest") {
35-
description = "Runs integration tests."
36-
group = "verification"
37-
38-
testClassesDirs = sourceSets["integrationTest"].output.classesDirs
39-
classpath = sourceSets["integrationTest"].runtimeClasspath
40-
shouldRunAfter("test")
41-
42-
useJUnitPlatform()
43-
44-
testLogging {
45-
events("passed")
46-
}
47-
48-
finalizedBy("jacocoIntegrationTestReport")
49-
}
50-
51-
dependencies {
52-
integrationTestImplementation(platform("com.codedifferently.studycrm.platform:java-test-platform"))
53-
integrationTestImplementation("org.junit.jupiter:junit-jupiter")
54-
integrationTestImplementation("org.mockito:mockito-core")
55-
integrationTestImplementation("org.springframework.boot:spring-boot-starter-test")
56-
integrationTestImplementation("org.springframework.security:spring-security-test")
57-
integrationTestRuntimeOnly("com.h2database:h2")
58-
integrationTestRuntimeOnly("org.junit.platform:junit-platform-launcher")
59-
}
60-
61-
tasks.register<JacocoReport>("jacocoIntegrationTestReport") {
62-
executionData(tasks.named("integrationTest").get())
63-
sourceSets(sourceSets["integrationTest"])
64-
65-
reports {
66-
xml.required.set(true)
67-
html.required.set(true)
68-
}
69-
}
70-
71-
tasks.jacocoTestReport {
72-
dependsOn("jacocoIntegrationTestReport")
73-
}
74-
75-
tasks.check {
76-
dependsOn(integrationTest)
77-
dependsOn("jacocoIntegrationTestReport")
7818
}

build-logic/java-shared/src/main/kotlin/com.codedifferently.studycrm.java-shared.gradle.kts

+32-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
plugins {
22
id("java")
3+
id("jvm-test-suite")
34
id("jacoco")
45
id("eclipse")
56
id("io.freefair.lombok")
@@ -39,16 +40,38 @@ configure<com.diffplug.gradle.spotless.SpotlessExtension> {
3940

4041
dependencies {
4142
implementation(platform("com.codedifferently.studycrm.platform:java-platform"))
43+
}
44+
45+
testing {
46+
suites {
47+
withType<JvmTestSuite> {
48+
useJUnitJupiter()
49+
dependencies {
50+
implementation(platform("com.codedifferently.studycrm.platform:java-test-platform"))
51+
implementation("org.mockito:mockito-junit-jupiter")
52+
runtimeOnly("com.h2database:h2")
53+
}
54+
}
4255

43-
testImplementation(platform("com.codedifferently.studycrm.platform:java-test-platform"))
44-
testImplementation("org.springframework.boot:spring-boot-starter-test")
45-
testImplementation("org.mockito:mockito-core")
46-
testImplementation("org.junit.jupiter:junit-jupiter")
47-
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
48-
testRuntimeOnly("com.h2database:h2")
56+
register<JvmTestSuite>("integrationTest") {
57+
testType = TestSuiteType.INTEGRATION_TEST
58+
59+
dependencies {
60+
implementation(project())
61+
runtimeOnly(project())
62+
}
63+
64+
targets {
65+
all {
66+
testTask.configure {
67+
shouldRunAfter(testing.suites.named("test"))
68+
}
69+
}
70+
}
71+
}
72+
}
4973
}
5074

51-
tasks.test {
52-
useJUnitPlatform()
53-
finalizedBy(tasks.jacocoTestReport)
75+
tasks.named("check") {
76+
dependsOn(testing.suites.named("integrationTest"))
5477
}

build-logic/spring-library/src/main/kotlin/com.codedifferently.studycrm.spring-library.gradle.kts

+10-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,15 @@ dependencies {
1111
implementation("org.springframework.boot:spring-boot-starter-security")
1212
implementation("org.springframework.boot:spring-boot-starter-validation")
1313
implementation("org.springframework.security:spring-security-acl")
14+
}
1415

15-
testImplementation("org.springframework.boot:spring-boot-starter-test")
16-
testImplementation("org.springframework.security:spring-security-test")
16+
testing {
17+
suites {
18+
withType<JvmTestSuite> {
19+
dependencies {
20+
implementation("org.springframework.boot:spring-boot-starter-test")
21+
implementation("org.springframework.security:spring-security-test")
22+
}
23+
}
24+
}
1725
}

build-logic/spring-web-library/src/main/kotlin/com.codedifferently.studycrm.spring-web-library.gradle.kts

+11-1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,15 @@ dependencies {
99
implementation("org.springframework.boot:spring-boot-starter-actuator")
1010
implementation("org.springframework.boot:spring-boot-starter-validation")
1111
runtimeOnly("org.springframework:spring-context-support")
12-
testImplementation("org.springframework.security:spring-security-test")
12+
}
13+
14+
testing {
15+
suites {
16+
withType<JvmTestSuite> {
17+
dependencies {
18+
implementation("org.springframework.boot:spring-boot-starter-test")
19+
implementation("org.springframework.security:spring-security-test")
20+
}
21+
}
22+
}
1323
}

build.gradle.kts

+29-9
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,20 @@ import com.avast.gradle.dockercompose.ComposeExtension
33
plugins {
44
`kotlin-dsl`
55
id("com.codedifferently.studycrm.java-shared")
6-
id("jacoco-report-aggregation")
76
id("com.avast.gradle.docker-compose") version "0.17.6"
7+
id("jacoco-report-aggregation")
8+
id("test-report-aggregation")
89
}
910

1011
repositories {
1112
mavenCentral()
1213
}
1314

1415
dependencies {
15-
// Load bearing deps needed to aggregate jacoco reports.
16-
implementation("com.codedifferently.studycrm.auth-service.main:auth-main-app")
17-
implementation("com.codedifferently.studycrm.contact-service.main:contact-main-app")
18-
implementation("com.codedifferently.studycrm.organization-service.main:organization-main-app")
16+
// Load bearing deps needed to aggregate coverage reports.
17+
jacocoAggregation("com.codedifferently.studycrm.auth-service.main:auth-main-app")
18+
jacocoAggregation("com.codedifferently.studycrm.contact-service.main:contact-main-app")
19+
jacocoAggregation("com.codedifferently.studycrm.organization-service.main:organization-main-app")
1920
}
2021

2122
val eventuateCommonImageVersion: String by project
@@ -82,11 +83,30 @@ tasks.test {
8283
}
8384
}
8485

85-
// Ensure that we generate the jacoco report for the repo.
86-
tasks.check {
87-
dependsOn(tasks.named<JacocoReport>("testCodeCoverageReport"))
86+
reporting {
87+
reports {
88+
val testFullCodeCoverageReport by creating(JacocoCoverageReport::class) {
89+
testType = TestSuiteType.PERFORMANCE_TEST
90+
}
91+
}
92+
}
93+
94+
tasks.named<JacocoReport>("testFullCodeCoverageReport") {
95+
description = "Build a full test coverage report including test and integrationTest results"
96+
dependsOn( "testCodeCoverageReport", "integrationTestCodeCoverageReport" )
97+
executionData.setFrom(fileTree( project.rootDir.absolutePath ).include( "**/build/jacoco/*.exec" ))
98+
99+
reports {
100+
xml.required = true
101+
html.required = true
102+
}
88103
}
89104

90105
tasks.register("coverage") {
91-
dependsOn("testCodeCoverageReport")
106+
dependsOn(tasks.named("testFullCodeCoverageReport"))
107+
}
108+
109+
// Ensure that we generate the coverage report for the repo.
110+
tasks.check {
111+
dependsOn(tasks.named("coverage"))
92112
}

platforms/java-test-platform/build.gradle.kts

+5-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ group = "com.codedifferently.studycrm.platform"
88
javaPlatform.allowDependencies()
99

1010
val mockitoVersion: String by project
11+
val springBootVersion: String by project
12+
val junitBomVersion: String by project
1113

1214
dependencies {
13-
api(platform("org.junit:junit-bom:5.7.1"))
14-
15+
api(platform("org.junit:junit-bom:$junitBomVersion"))
16+
api(platform("org.springframework.boot:spring-boot-dependencies:$springBootVersion"))
1517
api(platform("org.mockito:mockito-core:$mockitoVersion"))
18+
api(platform("org.mockito:mockito-junit-jupiter:$mockitoVersion"))
1619
}
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
mockitoVersion=5.10.0
1+
junitBomVersion=5.7.1
2+
mockitoVersion=5.10.0
3+
springBootVersion=3.2.2

0 commit comments

Comments
 (0)