I have an existing application that I have wrapped inside a spring boot application to provide it with a REST API. The application uses JUnit at its core to run some tests (I am aware this is not conventional).
Since the introduction of Spring Boot, the application is no longer able to find the jupiter-engine
and my test methods.
Interestingly enough, running the application from the IDE (Intellij) works fine. But as a standalone jar (java -jar
), it does not.
I looked in the packaged jar, everything is stored in the BOOT-INF
directory. Without Spring, the directory structure is flatter without the BOOT-INF
directory (obviously).
My test cases are stored in the package scenarios
. My application is in com.foo.bar.app
. Note that my test cases are in the main
package and not in the test
package.
(Again, I know it's unconventional, but they are not regular unit tests.)
I used to discover test cases with
LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder
.request()
.selectors(DiscoverySelectors.selectPackage("scenarios"))
.build();
However, with spring I am only able to discover them as follows.
LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder
.request()
.selectors(DiscoverySelectors.selectPackage(""))
.build();
Yet, the launcher is not able to launch the TestPlan
since it can't find the engine. I am getting the feeling that JUnit
is looking in a hardcoded path, which is outside of the BOOT-INF
directory.
I did some additional testing and I found that
DiscoverySelectors.selectMethod(className + "#" + method)
fails with
Could not load class with name: scenarios.path.to.class
The test class is packaged together with the application, but it's in the BOOT-INF
directory.
Are there some configurations I am missing?
question from:
https://stackoverflow.com/questions/65935140/junit-can-not-discover-test-programatically-inside-a-spring-boot-application-pac