How to run JUnit test cases from the command line

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

    If your project is Maven-based you can run all test-methods from test-class CustomTest which belongs to module 'my-module' using next command:

    mvn clean test -pl :my-module -Dtest=CustomTest
    

    Or run only 1 test-method myMethod from test-class CustomTest using next command:

    mvn clean test -pl :my-module -Dtest=CustomTest#myMethod
    

    For this ability you need Maven Surefire Plugin v.2.7.3+ and Junit 4. More details is here: http://maven.apache.org/surefire/maven-surefire-plugin/examples/single-test.html

提交回复
热议问题