[Question] Run JUnit4 commandline against a fat jar.
See original GitHub issueI am new to the JVM world and hence don’t know much about it. Though it’s not stackoverflow.com, I hope you guys can point me to the right direction.
Here is an issue I am trying to tackle:
I have a fat jar that has a JUnit4 test class. I can run it in gradle and it works just fine. However what I would like to do is have a run it from a commandline. I read the documentation and can see that one can run tests per class. But I need the to be discovered automatically from the jar file, same way as gradle does it.
What I tried so far:
> java -cp .;junit-4.12.jar;hamcrest-core-1.3.jar org.junit.runner.JUnitCore ./build/libs/fatjar.jar
JUnit version 4.12
.E
Time: 0.003
There was 1 failure:
1) initializationError(org.junit.runner.JUnitCommandLineParseResult)
java.lang.IllegalArgumentException: Could not find class [./build/libs/fatjar.jar]
at org.junit.runner.JUnitCommandLineParseResult.parseParameters(JUnitCommandLineParseResult.java:102)
at org.junit.runner.JUnitCommandLineParseResult.parseArgs(JUnitCommandLineParseResult.java:50)
at org.junit.runner.JUnitCommandLineParseResult.parse(JUnitCommandLineParseResult.java:44)
at org.junit.runner.JUnitCore.runMain(JUnitCore.java:72)
at org.junit.runner.JUnitCore.main(JUnitCore.java:36)
Caused by: java.lang.ClassNotFoundException: ./build/libs/fatjar.jar
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.junit.internal.Classes.getClass(Classes.java:16)
at org.junit.runner.JUnitCommandLineParseResult.parseParameters(JUnitCommandLineParseResult.java:100)
... 4 more
FAILURES!!!
Tests run: 1, Failures: 1
Obviously this didn’t work, as the runner is expecting a class name and not a jar file.
Is it actually possible? May it be possible with JUnit5 runner?
Thanks in advance.
P.S.
In case it helps, this is the project: https://github.com/albumprinter/junit-synnefo-demo
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
JUnit 4 doesn’t have built-in support for this, but there are third-party options. One of them is https://github.com/takari/takari-cpsuite (that’s apparently the new home for https://blog.johanneslink.net/2006/11/14/classpathsuite-for-junit4/)
yeah, I figured that out, too. thanks!
The thing is that I have a few classes I want to run. I guess
ClasspathSuite
might be an option.I am also looking at using gradle for it: run the tests from the compiled jar. I have a working prototype already.