I would like to run JUnit test cases from the command line. How can I do this?
相关问题
- Dependencies while implementing Mocking in Junit4
- How to unit test a reactive component where ngCont
- org.apache.commons.fileupload.disk.DiskFileItem is
- softlinks atime and mtime modification
- Access for global variables JavaScript unit testin
相关文章
- How to replace file-access references for a module
- How to mock methods return object with deleted cop
- What is a good way of cleaning up after a unit tes
-
EF6 DbSet
returns null in Moq - React testing library: Test attribute / prop
- Setup and Tear Down of Complex Database State With
- React/JestJS/Enzyme: How to test for ref function?
- Compile and build with single command line Java (L
Personally I would use the Maven surefire JUnit runner to do that.
Alternatively you can use the following methods in JunitCore class http://junit.sourceforge.net/javadoc/org/junit/runner/JUnitCore.html
run (with Request , Class classes and Runner) or runClasses from your java file.
Actually you can also make the Junit test a runnable Jar and call the runnable jar as java -jar
For JUnit 5.x it's:
Find a brief summary at https://stackoverflow.com/a/52373592/1431016 and full details at https://junit.org/junit5/docs/current/user-guide/#running-tests-console-launcher
For JUnit 4.X it's really:
But if you are using JUnit 3.X note the class name is different:
You might need to add more JARs or directories with your class files to the classpath and separate that with semicolons (Windows) or colons (UNIX/Linux). It depends on your environment.
Edit: I've added current directory as an example. Depends on your environment and how you build your application (can be bin/ or build/ or even my_application.jar etc). Note Java 6+ does support globs in classpath, you can do:
Hope it helps. Write tests! :-)
In windows it is
java -cp .;/path/junit.jar org.junit.runner.JUnitCore TestClass
[test class name without .class extension]for example:
c:\>java -cp .;f:/libraries/junit-4.8.2 org.junit.runner.JUnitCore TestSample1 TestSample2 ...
and so on, if one has more than one test classes.-cp stands for class path and the dot (.) represents the existing classpath while semi colon (;) appends the additional given jar to the classpath , as in above example junit-4.8.2 is now available in classpath to execute JUnitCore class that here we have used to execute our test classes.
Above command line statement helps you to execute junit (version 4+) tests from command prompt(i-e MSDos).
Note: JUnitCore is a facade to execute junit tests, this facade is included in 4+ versions of junit.