Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ repository on GitHub.
to avoid conflicts with other control characters.
* Fix `IllegalAccessError` thrown when using the Kotlin-specific `assertDoesNotThrow`
assertion.
* Stop reporting discovery issues for synthetic methods, particularly in conjunction with
Kotlin suspend functions.

[[release-notes-6.0.1-junit-jupiter-deprecations-and-breaking-changes]]
==== Deprecations and Breaking Changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ abstract class IsTestableMethod implements Predicate<Method> {

@Override
public boolean test(Method candidate) {
if (isAnnotated(candidate, this.annotationType)) {
if (!candidate.isSynthetic() && isAnnotated(candidate, this.annotationType)) {
return condition.check(candidate) && isNotAbstract(candidate);
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private static Try<Class<? extends Annotation>> tryToLoadKotlinMetadataClass() {
*/
@API(status = INTERNAL, since = "6.0")
public static boolean isKotlinSuspendingFunction(Method method) {
if (kotlinCoroutineContinuation != null && isKotlinType(method.getDeclaringClass())) {
if (!method.isSynthetic() && kotlinCoroutineContinuation != null && isKotlinType(method.getDeclaringClass())) {
int parameterCount = method.getParameterCount();
return parameterCount > 0 //
&& method.getParameterTypes()[parameterCount - 1] == kotlinCoroutineContinuation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ class KotlinSuspendFunctionsTests : AbstractJupiterTestEngineTests() {
assertThat(getPublishedEvents(results)).containsExactly("test")
}

@Test
fun suspendingOpenTestMethodsAreSupported() {
val results = executeTestsForClass(OpenTestMethodTestCase::class)
assertAllTestsPassed(results, 1)
assertThat(getPublishedEvents(results)).containsExactly("test")
}

@Test
fun suspendingTestTemplateMethodsAreSupported() {
val results = executeTestsForClass(TestTemplateTestCase::class)
Expand Down Expand Up @@ -187,6 +194,14 @@ class KotlinSuspendFunctionsTests : AbstractJupiterTestEngineTests() {
}
}

@Suppress("JUnitMalformedDeclaration")
open class OpenTestMethodTestCase {
@Test // https://github.com/junit-team/junit-framework/issues/5102
open suspend fun `check getRandomPositiveInt`(reporter: TestReporter) {
suspendingPublish(reporter, "test")
}
}

@Suppress("RedundantSuspendModifier")
companion object {
suspend fun suspendingPublish(
Expand Down
3 changes: 2 additions & 1 deletion platform-tests/platform-tests.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import org.gradle.plugins.ide.eclipse.model.Classpath
import org.gradle.plugins.ide.eclipse.model.SourceFolder

plugins {
id("junitbuild.java-library-conventions")
id("junitbuild.kotlin-library-conventions")
id("junitbuild.junit4-compatibility")
id("junitbuild.testing-conventions")
id("junitbuild.jmh-conventions")
Expand Down Expand Up @@ -54,6 +54,7 @@ dependencies {
testImplementation(libs.openTestReporting.tooling.core)
testImplementation(libs.picocli)
testImplementation(libs.bundles.xmlunit)
testImplementation(kotlin("stdlib"))
testImplementation(testFixtures(projects.junitJupiterApi))
testImplementation(testFixtures(projects.junitPlatformReporting))
testImplementation(projects.platformTests) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright 2015-2025 the original author or authors.
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v2.0 which
* accompanies this distribution and is available at
*
* https://www.eclipse.org/legal/epl-v20.html
*/
package org.junit.platform.commons.util

import org.junit.jupiter.api.Assertions.assertFalse
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test
import org.junit.platform.commons.support.ModifierSupport
import kotlin.coroutines.Continuation

class KotlinReflectionUtilsTests {
@Test
fun recognizesSuspendFunction() {
val method =
OpenTestMethodTestCase::class.java.getDeclaredMethod(
"test",
Continuation::class.java
)

assertFalse(ModifierSupport.isStatic(method))
assertFalse(method.isSynthetic)

assertTrue(KotlinReflectionUtils.isKotlinSuspendingFunction(method))
}

@Test
fun doesNotRecognizeSyntheticMethodAsSuspendFunction() {
val method =
OpenTestMethodTestCase::class.java.getDeclaredMethod(
"test\$suspendImpl",
OpenTestMethodTestCase::class.java,
Continuation::class.java
)

assertTrue(ModifierSupport.isStatic(method))
assertTrue(method.isSynthetic)

assertFalse(KotlinReflectionUtils.isKotlinSuspendingFunction(method))
}

@Suppress("JUnitMalformedDeclaration")
open class OpenTestMethodTestCase {
@Test
open suspend fun test() {
}
}
}