2

I have a fat JAR called smoke-tests-fat-1.0.0-SNAPSHOT.jar containing JUnit 5 tests. The tests are annotated with org.junit.jupiter.api.Test at the method level.

I now want to execute these tests with the JUnit 5 Console Launcher. However, it seems that I can't get it right.

I have tried:

  • java -jar junit-platform-console-standalone.jar --classpath smoke-tests-fat-1.0.0-SNAPSHOT.jar --scan-classpath
  • java -jar junit-platform-console-standalone.jar --classpath smoke-tests-fat-1.0.0-SNAPSHOT.jar --select-package=my.package

But neither command works. The Console Launcher never finds any tests.

How can I get the Console Launcher to execute my JUnit 5 tests contained in the JAR?

Harold L. Brown
  • 8,423
  • 11
  • 57
  • 109

2 Answers2

0

According to this tested answer https://stackoverflow.com/a/52373592/1431016 it should work the way you tried.

  • Are your test classes named like the default test class name pattern mandates? I.e. start with Test or end with Test[s]?
  • Is the content of the fat JAR file packaged correctly? I.e. matching directory tree and package name structure?

If your test classes follow a different naming pattern, you may, instead of renaming them, pass your pattern to the console launcher via the -n, --include-classname=PATTERN option:

--include-classname=PATTERN
                             Provide a regular expression to include only classes whose
                               fully qualified names match. To avoid loading classes
                               unnecessarily, the default pattern only includes class
                               names that begin with "Test" or end with "Test" or
                               "Tests". When this option is repeated, all patterns will
                               be combined using OR semantics. Default: [^(Test.*|.+[.$]
                               Test.*|.*Tests?)$]
Sormuras
  • 8,491
  • 1
  • 38
  • 64
0

Something like this

        LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request()
            .selectors(
                    selectPackage("com.bla.blapackage")          
            )
            .filters(
                    includeClassNamePatterns(ClassNameFilter.STANDARD_INCLUDE_PATTERN)
            )
            .build();

Or for spring-boot fat jar , which is actually not fat jar , need to select each class.

            LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request()
            .selectors(
                   
                    selectClass(ValidationTest.class)
            )

            .build();
Igor Azarny
  • 124
  • 1
  • 3