Skip to content

Commit

Permalink
Fix source set inheritance
Browse files Browse the repository at this point in the history
  • Loading branch information
radoslaw-panuszewski authored and pmendelski committed Oct 16, 2024
1 parent a54adec commit 3625f2e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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) {
Expand Down Expand Up @@ -116,7 +119,7 @@ class Junit5BasedAcceptanceTest {
}
@Test
public void shouldReadCTxtFileFromTest() {
public void shouldReadCTxtFileFromIntegration() {
assertEquals("integration-c", readFile("c.txt"));
}
Expand All @@ -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(
Expand Down

0 comments on commit 3625f2e

Please sign in to comment.