如何从命令行运行JUnit测试用例 [英] How to run JUnit test cases from the command line
问题描述
我想从命令行运行JUnit测试用例。
I would like to run JUnit test cases from the command line. How can I do this?
推荐答案
java -cp .:/usr/share/java/junit.jar org.junit.runner.JUnitCore [test class name]
但如果您使用 JUnit 3.X 是不同的:
But if you are using JUnit 3.X note the class name is different:
java -cp .:/usr/share/java/junit.jar junit.textui.TestRunner [test class name]
您可能需要在类路径中添加更多的JAR或目录,使用分号(Windows)或冒号(UNIX / Linux)。这取决于您的环境。
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.
编辑:我已经添加了当前目录作为示例。取决于您的环境和如何构建您的应用程序(可以是bin /或build /或甚至my_application.jar等)。注意Java 6+在类路径中支持globs,你可以这样做:
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:
java -cp lib/*.jar:/usr/share/java/junit.jar ...
希望它有帮助。 写测试!: - )
Hope it helps. Write tests! :-)
这篇关于如何从命令行运行JUnit测试用例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!