How to run external testcase(Class,junit) in java program?

牧云@^-^@ 提交于 2020-02-01 03:28:36

问题


How to run external testcase(Class,junit) in java program?


回答1:


If you want to run JUnit tests through a Java program, you could use the JUnitCore class

JUnitCore is a facade for running tests.
It supports running JUnit 4 tests, JUnit 3.8.x tests, and mixtures.
To run tests from the command line, run:

(windows)

java -cp /path/to/junit.jar;/path/to/yourTextClasses org.junit.runner.JUnitCore TestClass1 TestClass2 .... 

(Unix)

java -cp /path/to/junit.jar:/path/to/yourTextClasses org.junit.runner.JUnitCore TestClass1 TestClass2 .... 

For one-shot test runs, use the static method runClasses(Class[]).

Make sure you have junit.jar in your classpath, and the jar or classes of your external tests also in the the classpath.

That way you can execute them from the command-line (which may not be what you are after) or directly within your java program.

JUnitCore.runClasses(TestClass1,TestClass2,...)


来源:https://stackoverflow.com/questions/1197882/how-to-run-external-testcaseclass-junit-in-java-program

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