如何在Java程序中运行外部测试用例(类,junit)? [英] How to run external testcase(Class,junit) in java program?
问题描述
如何在Java程序中运行外部测试用例(类,junit)?
How to run external testcase(Class,junit) in java program?
推荐答案
If you want to run JUnit tests through a Java program, you could use the JUnitCore class
JUnitCore是用于运行测试的外观.
它支持运行JUnit 4测试,JUnit 3.8.x测试和混合.
要从命令行运行测试,请运行:
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 ....
对于单次运行测试,请使用静态方法
runClasses(Class[])
.
确保在类路径中有junit.jar,并且在类路径中也有外部测试的jar或类.
Make sure you have junit.jar in your classpath, and the jar or classes of your external tests also in the the classpath.
这样,您可以从命令行(可能不是您想要的)或直接在Java程序中执行它们.
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,...)
这篇关于如何在Java程序中运行外部测试用例(类,junit)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!