diff --git a/src/main/kotlin/com/coditory/gradle/integration/TestSuitesConfiguration.kt b/src/main/kotlin/com/coditory/gradle/integration/TestSuitesConfiguration.kt index dba6a57..46d488f 100644 --- a/src/main/kotlin/com/coditory/gradle/integration/TestSuitesConfiguration.kt +++ b/src/main/kotlin/com/coditory/gradle/integration/TestSuitesConfiguration.kt @@ -40,24 +40,37 @@ internal object TestSuitesConfiguration { task.onlyIf { !skipUnitTest(project) } } } - testing.suites.register(INTEGRATION, JvmTestSuite::class.java) { - it.testType.set(TestSuiteType.INTEGRATION_TEST) - it.targets.all { target -> + testing.suites.register(INTEGRATION, JvmTestSuite::class.java) { testSuite -> + testSuite.testType.set(TestSuiteType.INTEGRATION_TEST) + testSuite.targets.all { target -> target.testTask.configure { task -> task.shouldRunAfter(test) task.onlyIf { !skipIntegrationTest(project) } } } - val sourceSets = project.extensions.getByType(JavaPluginExtension::class.java) - .sourceSets - val mainSourceSet = sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME) - val testSourceSet = sourceSets.getByName(SourceSet.TEST_SOURCE_SET_NAME) - it.sources.annotationProcessorPath += testSourceSet.annotationProcessorPath + mainSourceSet.annotationProcessorPath - it.sources.compileClasspath += testSourceSet.output + mainSourceSet.output + testSourceSet.compileClasspath - it.sources.runtimeClasspath += testSourceSet.output + mainSourceSet.output + testSourceSet.runtimeClasspath + setupIntegrationSourceSet(project, testSuite) } } + private fun setupIntegrationSourceSet(project: Project, testSuite: JvmTestSuite) { + val sourceSets = project.extensions.getByType(JavaPluginExtension::class.java).sourceSets + val mainSourceSet = sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME) + val testSourceSet = sourceSets.getByName(SourceSet.TEST_SOURCE_SET_NAME) + val integrationSourceSet = testSuite.sources + + project.configurations.getByName(integrationSourceSet.compileClasspathConfigurationName) + .extendsFrom(project.configurations.getByName(testSourceSet.compileClasspathConfigurationName)) + + project.configurations.getByName(integrationSourceSet.runtimeOnlyConfigurationName) + .extendsFrom(project.configurations.getByName(testSourceSet.runtimeClasspathConfigurationName)) + + project.configurations.getByName(integrationSourceSet.annotationProcessorConfigurationName) + .extendsFrom(project.configurations.getByName(testSourceSet.annotationProcessorConfigurationName)) + + integrationSourceSet.compileClasspath += testSourceSet.output + mainSourceSet.output + integrationSourceSet.runtimeClasspath += testSourceSet.output + mainSourceSet.output + } + private fun setupTestTask(project: Project) { val integrationTestTask = project.tasks.create(INTEGRATION_TEST) integrationTestTask.description = "Runs integration test suites." diff --git a/src/test/kotlin/com/coditory/gradle/integration/acceptance/Junit5BasedAcceptanceTest.kt b/src/test/kotlin/com/coditory/gradle/integration/acceptance/Junit5BasedAcceptanceTest.kt index 5e1358d..5741dc5 100644 --- a/src/test/kotlin/com/coditory/gradle/integration/acceptance/Junit5BasedAcceptanceTest.kt +++ b/src/test/kotlin/com/coditory/gradle/integration/acceptance/Junit5BasedAcceptanceTest.kt @@ -19,6 +19,7 @@ class Junit5BasedAcceptanceTest { import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; + import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static base.ClasspathFileReader.readFile; """.trimIndent() return project("sample-project") @@ -33,10 +34,12 @@ class Junit5BasedAcceptanceTest { } dependencies { + implementation platform("org.springframework.boot:spring-boot-dependencies:3.3.3") testImplementation "org.junit.jupiter:junit-jupiter-api:5.11.0" testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.11.0" // sample integration test dependency integrationImplementation "org.slf4j:slf4j-api:2.0.16" + integrationImplementation "org.springframework.boot:spring-boot-starter-test" } tasks.withType(Test) { @@ -116,7 +119,7 @@ class Junit5BasedAcceptanceTest { } @Test - public void shouldReadCTxtFileFromTest() { + public void shouldReadCTxtFileFromIntegration() { assertEquals("integration-c", readFile("c.txt")); } @@ -129,6 +132,13 @@ class Junit5BasedAcceptanceTest { public void shouldReadConstantValueFromMainModule() { assertEquals("main", MainConstantValues.MODULE); } + + @Test + void shouldResolveDependencyFromBom() { + assertDoesNotThrow( + () -> Class.forName("org.springframework.test.context.ContextConfiguration") + ); + } } """, ).withFile(