Uploaded image for project: 'Maven Surefire'
  1. Maven Surefire
  2. SUREFIRE-1549

Surefire outputs jmockit exception before forking and running JUnit5 / Java 10 tests successfully.

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 2.22.0
    • None
    • None

    Description

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

       

      [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] ------------------------------------------------------------------------
       
      

      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.

       

      Attachments

        1. sample.zip
          2 kB
          Bret Goldsmith

        Activity

          People

            Unassigned Unassigned
            bretg Bret Goldsmith
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: