You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
de.jodamob.kotlin.testrunner.NoMoreFinalsClassLoader uses Javassist which tries to make protected java.lang.ClassLoader.defineClass accessible. Due to JEP-396, this is forbidden since JDK 16 and cannot be overriden by any --add-opens call either.
Please update the product in order to use another API.
FYI, I use Spock and my workaround for ignoring tests using SpotlinTestRunner on JDK 16+ looks as follows, using a delegation pattern:
The Spock spec still needs an @IgnoreIf or @Requires in addition to @RunWith(JEP396AwareSpotlinTestRunner), but otherwise no changes are required. It can even utilise a constant JEP396AwareSpotlinTestRunner.hasJEP396 for its own condition:
packagede.scrum_master.stackoverflowimportde.jodamob.kotlin.testrunner.OpenedClassesimportde.jodamob.kotlin.testrunner.OpenedPackagesimportde.scrum_master.testing.JEP396AwareSpotlinTestRunnerimportorg.junit.runner.RunWithimportspock.lang.IgnoreIfimportspock.lang.Specification/** * See https://stackoverflow.com/q/48391716/1082681 * See https://github.com/dpreussler/kotlin-testrunner */@RunWith(JEP396AwareSpotlinTestRunner)
@IgnoreIf({ JEP396AwareSpotlinTestRunner.hasJEP396 })
@OpenedClasses(FinalClass)
//@OpenedPackages("de.scrum_master.stackoverflow")classAnotherClassSpotlinRunnerTestextendsSpecification {
def"use SpotlinRunner to stub final method in final class"() {
given:
FinalClassfinalClass = Stub() {
finalMethod() >> "mocked"
}
expect:
newAnotherClass().doSomething(finalClass) == "mocked"
}
}
The workaround is necessary, because JUnit 4 runners are initialised very early in the lifecycle, even before SpockConfig.groovy or global Spock extensions, even more so before @IgnoreIf and @Requires can kick in.
This is ugly, of course. There are alternatives to the Kotlin test runner, e.g. my own tool Sarek which can do a lot of fancy things, unfinalising classes for JUnit 4/5, TestNG and Spock just being one of them. But before I developed it, I was using your tool in Spock 1.3 and today just noticed that my old example code was no longer when running on JDK 16. So I thought, I take some time to create this issue, FWIW.
The text was updated successfully, but these errors were encountered:
de.jodamob.kotlin.testrunner.NoMoreFinalsClassLoader
uses Javassist which tries to makeprotected java.lang.ClassLoader.defineClass
accessible. Due to JEP-396, this is forbidden since JDK 16 and cannot be overriden by any--add-opens
call either.Please update the product in order to use another API.
FYI, I use Spock and my workaround for ignoring tests using
SpotlinTestRunner
on JDK 16+ looks as follows, using a delegation pattern:The Spock spec still needs an
@IgnoreIf
or@Requires
in addition to@RunWith(JEP396AwareSpotlinTestRunner)
, but otherwise no changes are required. It can even utilise a constantJEP396AwareSpotlinTestRunner.hasJEP396
for its own condition:The workaround is necessary, because JUnit 4 runners are initialised very early in the lifecycle, even before
SpockConfig.groovy
or global Spock extensions, even more so before@IgnoreIf
and@Requires
can kick in.This is ugly, of course. There are alternatives to the Kotlin test runner, e.g. my own tool Sarek which can do a lot of fancy things, unfinalising classes for JUnit 4/5, TestNG and Spock just being one of them. But before I developed it, I was using your tool in Spock 1.3 and today just noticed that my old example code was no longer when running on JDK 16. So I thought, I take some time to create this issue, FWIW.
The text was updated successfully, but these errors were encountered: