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

Support running unit tests in named Java 9 modules



    • New Feature
    • Status: Closed
    • Major
    • Resolution: Duplicate
    • None
    • None
    • None
    • None


      As far as I can tell, Surefire will run tests using the traditional classpath also on Java 9. When the project that is built is a named Java 9 module (i.e. it contains a module descriptor), it'd be desirable to have a way to run the tests using the module path instead.

      For that, the following things would be required:

      • Adding the currently built project and its dependencies to the module path instead of the class path when forking the java process running the tests
      • Adding a read edge from the currently built module to the used testing library, e.g. JUnit, if it's not present as a dependence in the module descriptor already (which it usually won't)
      • Patching the classes from target/test-classes into the currently built module (as represented by the classes under target/classes)
      • Opening up packages containing tests to the testing library so they can be accessed reflectively

      I could perform these steps manually by applying the following configuration for the Surefire plug-in:

              <!-- Don't add any dependencies to the class path -->
                       --add-modules com.example,junit,hamcrest.core
                       --add-reads com.example=junit
                       --add-opens com.example/com.example.internal=junit
                       --patch-module com.example=target/test-classes</argLine>
              <!-- Prevents target/classes to be added to the classpath -->                
              <!-- Doing the same for test classes failed as it caused no tests to be found; it still works, 
                    I assume the --patch-module above takes precedence over their occurrence on the classpath -->
              <!-- <testClassesDirectory>path/to/none</testClassesDirectory> -->

      Ideally, an equivalent java invocation would be done by Surefire automatically when building a named module.


        Issue Links



              rfscholte Robert Scholte
              gunnar.morling Gunnar Morling
              0 Vote for this issue
              3 Start watching this issue