How to run JUnit tests for Java from the command line [duplicate]

空扰寡人 提交于 2019-12-20 14:44:32

问题


Possible Duplicate:
How to run Junit testcases from command line?

I've run my JUnit tests using maven before. Now I'm packaging all my source code into a JAR file, and want to run it using a java command. How can I do that? Note that there is no main class in my code.


回答1:


You need to make sure the classpath contains

  1. Your JAR
  2. The JUnit JAR

You can set the class path by using the -cp flag to the java command. Then you can use junit.textui.TestRunner to run the tests.

If you're using Linux (note the use of : as the path separator between jars)

java -cp /path/to/my.jar:/path/to/junit.jar junit.textui.TestRunner com.mypackage.MyClassWithUnitTests

If you're using Windows (note the use of ; as the path separator between jars)

java -cp /path/to/my.jar;/path/to/junit.jar junit.textui.TestRunner com.mypackage.MyClassWithUnitTests


来源:https://stackoverflow.com/questions/7902983/how-to-run-junit-tests-for-java-from-the-command-line

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!