How can we use Junit test without eclipse

2019-08-16 02:12发布

问题:

I have wrote a piece of code in Junit. I need to run it without eclipse. Any suggestions how can I do that ?

回答1:

Since Eclipse 2018-09 in Java Application and JUnit launch configurations there is a button Show Command Line for that.

See also: video that shows this feature in action



回答2:

Yes, you have an option to run your test cases in command line,

Example:

As you are running the mvn clean install for building your application, In the same way, you can also run your test cases as well by using the command.

1. Command to compile your test class >> **javac -cp junit-4.12.jar;. UserDAOTest.java ProductDAOTest.java** --> general command is >> **javac -cp <junit-jar-file>;. TestClass1.java TestClass2.java**
2. Run the test cases >> ** java -cp <junit-jar>;<hamcrest-jar>;. org.junit.runner.JUnitCore  TestClass1 TestClass2 **
3. Running the unit test cases by Maven Command Line >> mvn test >> mvn clean test >> mvn clean compile test


标签: eclipse junit