-
Notifications
You must be signed in to change notification settings - Fork 6.4k
[Gradle] Add integration tests for KMP test execution, aggregation, and failure reporting #7620
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Yermukhamed Shakhman (ermawqa-jetbrains)
wants to merge
4
commits into
master
Choose a base branch
from
yermukhamed/kmp-test-reports-integration-tests
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c204fcf
add test case: kmp test aggregation ":allTests"
ermawqa-jetbrains 804ee9e
add test case: fixture with lightweight jvm + js setup with disabled …
ermawqa-jetbrains d316609
add Smoke test annotation because it can be affected by other domains
ermawqa-jetbrains 151b67b
remove redundant .removePrefix(..) method
ermawqa-jetbrains File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
134 changes: 134 additions & 0 deletions
134
...ugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/mpp/MppTestReportIT.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| /* | ||
| * Copyright 2010-2026 JetBrains s.r.o. and Kotlin Programming Language contributors. | ||
| * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. | ||
| */ | ||
|
|
||
| package org.jetbrains.kotlin.gradle.mpp | ||
|
|
||
| import org.gradle.util.GradleVersion | ||
| import org.jetbrains.kotlin.gradle.testbase.* | ||
| import org.jetbrains.kotlin.testFederation.SmokeTest | ||
| import org.junit.jupiter.api.DisplayName | ||
| import kotlin.test.assertEquals | ||
| import kotlin.test.assertNotNull | ||
| import kotlin.test.assertTrue | ||
|
|
||
| @MppGradlePluginTests | ||
| @SmokeTest | ||
| @DisplayName("Tests for KMP test reporting") | ||
| class MppTestReportIT : KGPBaseTest() { | ||
|
|
||
| @DisplayName("Aggregated test report contains results from multiple targets (:allTests)") | ||
| @GradleTest | ||
| fun testAllTestsReportAggregation(gradleVersion: GradleVersion) { | ||
| project( | ||
| "base-kotlin-multiplatform-library", | ||
| gradleVersion, | ||
| buildOptions = defaultBuildOptions.disableIsolatedProjectsBecauseOfJsAndWasmKT75899(), | ||
| ) { | ||
| buildScriptInjection { | ||
| kotlinMultiplatform.jvm() | ||
| kotlinMultiplatform.js { | ||
| nodejs() | ||
| } | ||
| kotlinMultiplatform.sourceSets.getByName("commonTest").dependencies { | ||
| implementation(kotlin("test")) | ||
| } | ||
| } | ||
|
|
||
| kotlinSourcesDir("commonTest").source("org/example/project/SampleTest.kt") { | ||
| """ | ||
| package org.example.project | ||
|
|
||
| import kotlin.test.Test | ||
| import kotlin.test.assertTrue | ||
|
|
||
| class SampleTest { | ||
| @Test | ||
| fun testOne() { | ||
| assertTrue(true) | ||
| } | ||
|
|
||
| @Test | ||
| fun testTwo() { | ||
| assertTrue(true) | ||
| } | ||
| } | ||
| """.trimIndent() | ||
| } | ||
|
|
||
| build(":allTests") { | ||
| assertTasksExecuted(":jvmTest", ":jsNodeTest", ":allTests") | ||
| } | ||
|
|
||
| assertFileInProjectExists("build/reports/tests/allTests/index.html") | ||
| assertExecutedTestCases( | ||
| ":jvmTest", | ||
| "org.example.project.SampleTest#testOne", | ||
| "org.example.project.SampleTest#testTwo", | ||
| ) | ||
| assertExecutedTestCases( | ||
| ":jsNodeTest", | ||
| "org.example.project.SampleTest#testOne", | ||
| "org.example.project.SampleTest#testTwo", | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| @DisplayName("Test failure details, stack trace anti-drift, and HTML report (:jvmTest)") | ||
| @GradleTest | ||
| fun testTestFailureReportingAndStackTrace(gradleVersion: GradleVersion) { | ||
| project( | ||
| "base-kotlin-multiplatform-library", | ||
| gradleVersion, | ||
| buildOptions = defaultBuildOptions.disableIsolatedProjectsBecauseOfJsAndWasmKT75899(), | ||
| ) { | ||
| buildScriptInjection { | ||
| kotlinMultiplatform.jvm() | ||
| kotlinMultiplatform.sourceSets.getByName("commonTest").dependencies { | ||
| implementation(kotlin("test")) | ||
| } | ||
| } | ||
|
|
||
| val testClass = "FailingTest" | ||
| val testPackage = "org.example.project" | ||
| val testSource = """ | ||
| package $testPackage | ||
|
|
||
| import kotlin.test.Test | ||
|
|
||
| class $testClass { | ||
| @Test | ||
| fun failing() { | ||
| throw IllegalStateException("boom") | ||
| } | ||
| } | ||
| """.trimIndent() | ||
|
|
||
| val throwingLine = testSource.lines().indexOfFirst { "throw" in it } + 1 | ||
|
|
||
| kotlinSourcesDir("commonTest").source("$testPackage/$testClass.kt") { | ||
| testSource | ||
| } | ||
|
|
||
| buildAndFail(":jvmTest") { | ||
| assertTasksFailed(":jvmTest") | ||
| } | ||
|
|
||
| val testCases = readTestCases(":jvmTest") | ||
| val failingTestCase = testCases.single { it.className == "$testPackage.$testClass" && it.name.startsWith("failing") } | ||
| val failure = failingTestCase.failure | ||
| assertNotNull(failure, "Expected failure information for test case") | ||
| assertEquals("java.lang.IllegalStateException", failure.type) | ||
| assertEquals("java.lang.IllegalStateException: boom", failure.message) | ||
| assertNotNull(failure.stackTrace, "Expected stack trace in test failure") | ||
| assertTrue( | ||
| failure.stackTrace.contains("$testPackage.$testClass.failing($testClass.kt:$throwingLine)"), | ||
| "Expected stack trace to contain '$testPackage.$testClass.failing($testClass.kt:$throwingLine)', but was:\n${failure.stackTrace}" | ||
| ) | ||
|
|
||
| val htmlReport = testClassHtmlReport(":jvmTest", "$testPackage.$testClass", gradleVersion, targetName = "jvm") | ||
| assertFileExists(htmlReport) | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As an alternative I think we can consider testing against a golden file here, I think this approach might be less brittle against potential HTML report formatting changes in future versions of Gradle.