How to run JUnit test cases from the command line

前端 未结 11 1570
花落未央
花落未央 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

    With JUnit 4.12 the following didn't work for me:

    java -cp .:/usr/share/java/junit.jar org.junit.runner.JUnitCore [test class name]
    

    Apparently, from JUnit 4.11 onwards you should also include hamcrest-core.jar in your classpath:

    java -cp .:/usr/share/java/junit.jar:/usr/share/java/hamcrest-core.jar org.junit.runner.JUnitCore [test class name]
    

提交回复
热议问题