Add an integration test for the test runs API

Issue #KT-32679
This commit is contained in:
Sergey Igushkin
2019-08-26 22:48:53 +03:00
parent d1016f0221
commit f0ef5a90b3
2 changed files with 88 additions and 1 deletions
@@ -2043,7 +2043,7 @@ class NewMultiplatformIT : BaseGradleIT() {
}
@Test
fun testAssociateCompilations() = with(Project("new-mpp-associate-compilations")) {
fun testAssociateCompilations() = with(Project("new-mpp-associate-compilations", GradleVersionRequired.AtLeast("5.0"))) {
setupWorkingDir()
gradleBuildScript().modify(::transformBuildScriptWithPluginsDsl)
@@ -2068,4 +2068,47 @@ class NewMultiplatformIT : BaseGradleIT() {
assertFileExists("build/classes/kotlin/$nativeHostTargetName/integrationTest/integrationTest.klib")
}
}
@Test
fun testTestRunsApi() = with(Project("new-mpp-associate-compilations", GradleVersionRequired.AtLeast("5.0"))) {
setupWorkingDir()
gradleBuildScript().modify(::transformBuildScriptWithPluginsDsl)
// TOOD: add Kotlin/JS tests once they can be tested without much performance overhead
val testTasks =
arrayOf(":jvmTest", ":${nativeHostTargetName}Test", ":jvmIntegrationTest", ":${nativeHostTargetName}IntegrationTest")
build(*testTasks) {
assertSuccessful()
assertTasksExecuted(
*testTasks,
":compileIntegrationTestKotlinJvm",
":linkIntegrationDebugTest${nativeHostTargetName.capitalize()}"
)
fun checkUnitTestOutput(targetName: String) {
val classReportHtml = projectDir
.resolve("build/reports/tests/${targetName}Test/classes/com.example.HelloTest.html")
.readText()
if (targetName != nativeHostTargetName) // TODO: fix exclude patterns for the Kotlin/Native test tasks
assertTrue("secondTest" !in classReportHtml, "Test report should not contain 'secondTest':\n$classReportHtml")
}
checkUnitTestOutput("jvm")
checkUnitTestOutput(nativeHostTargetName)
fun checkIntegrationTestOutput(targetName: String) {
val classReportHtml = projectDir
.resolve("build/reports/tests/${targetName}IntegrationTest/classes/com.example.HelloIntegrationTest.html")
.readText()
assertTrue("test[$targetName]" in classReportHtml, "Test report should contain 'test[$targetName]':\n$classReportHtml")
assertTrue("secondTest" !in classReportHtml, "Test report should not contain 'secondTest':\n$classReportHtml")
assertTrue("thirdTest" !in classReportHtml, "Test report should not contain 'thirdTest':\n$classReportHtml")
}
checkIntegrationTestOutput("jvm")
checkIntegrationTestOutput(nativeHostTargetName)
}
}
}
@@ -53,4 +53,48 @@ kotlin {
defaultSourceSet.dependsOn(sourceSets["commonIntegrationTest"])
}
}
}
kotlin {
testableTargets.all {
testRuns {
getByName("test") {
filter {
excludeTestsMatching("*.secondTest")
}
}
create("integration") {
filter {
includeTestsMatching("com.example.HelloIntegrationTest.test")
}
}
}
}
jvm {
testRuns {
getByName("test").filter {
excludeTestsMatching("com.example.HelloTest.secondTest")
}
getByName("integration") {
setExecutionSourceFrom(compilations["integrationTest"])
}
}
}
targets.matching { it.name == "mingw64" || it.name == "linux64" || it.name == "macos64" }.all {
testRuns {
getByName("test").filter { excludeTestsMatching("*.secondTest") }
getByName("integration") {
binaries {
test("integration") {
compilation = compilations["integrationTest"]
}
}
setExecutionSourceFrom(binaries.getTest("integration", "DEBUG"))
}
}
}
}