[Created] (SUREFIRE-1549) Surefire outputs jmockit exception before forking and running JUnit5 / Java 10 tests successfully.

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[Created] (SUREFIRE-1549) Surefire outputs jmockit exception before forking and running JUnit5 / Java 10 tests successfully.

JIRA jira@apache.org
Bret Goldsmith created SUREFIRE-1549:
----------------------------------------

             Summary: Surefire outputs jmockit exception before forking and running JUnit5 / Java 10 tests successfully.
                 Key: SUREFIRE-1549
                 URL: https://issues.apache.org/jira/browse/SUREFIRE-1549
             Project: Maven Surefire
          Issue Type: Bug
          Components: JUnit 5.x support, Maven Surefire Plugin
    Affects Versions: 2.22.0
         Environment: Apache Maven 3.5.3 (3383c37e1f9e9b3bc3df5050c29c8aff9f295297; 2018-02-24T13:49:05-06:00)
Java version: 10.0.2, vendor: Oracle Corporation
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"

            Reporter: Bret Goldsmith
         Attachments: sample.zip

Running this test shows an exception on the build output, but does not affect the actual running of the forked tests.

 
{noformat}
[INFO] --- maven-surefire-plugin:2.22.0:test (default-test) @ sample ---
[INFO]
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
java.lang.IllegalStateException: Running on JDK 9 requires -javaagent:<proper path>/jmockit-1.n.jar or -Djdk.attach.allowAttachSelf
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:154)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:146)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
        at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:956)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:290)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:194)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
[INFO] Running SampleTest
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.037 s - in SampleTest
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
 
{noformat}
Test project attached that recreates the issue.

The "-Djdk.attach.allowAttachSelf" config is being passed to the forked runtime and allows the tests to pass, as indicated in the sample project's pom.xml, under the surefire config.

I'm not sure if this is a surefire issue, a junit5 issue, or a jmockit issue, but I think it's a bit of a combination (and consequently have no idea what the right "fix" would target).

After some basic investigation, it looks like Surefire is kicking off the JUnitPlatformProvider, which calls out to LauncherFactory, and all this happens before the fork takes place where the test execution actually runs.  At this point, there is some awareness by the code on whether it is running inside a fork or not, and seems to be the part that is trying to look at the various tests in the codebase.  At some point, the JMockitTestEngine class gets initialized by the LauncherFactory, and the LauncherFactory is not passing down the context of whether this is running inside a fork or not.  JMockit is not aware and tries to attach to the JVM that was invoked by maven.  Forking the tests is supposed to avoid that and allow all that config to be passed to the forked JVM, which is working fine.  The exception still gets output to the console, and is an annoyance.

 



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)