How to run JUnit test cases from the command line

前端 未结 11 1759
花落未央
花落未央 2020-11-22 02:09

I would like to run JUnit test cases from the command line. How can I do this?

11条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-22 02:29

    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.

提交回复
热议问题