如何在java程序中运行外部测试用例(Class,junit)?
最佳答案
如果您想通过 Java 程序运行 JUnit 测试,您可以使用 JUnitCore 类
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:
( window )
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[])
.
确保您的类路径中有 junit.jar,并且外部测试的 jar 或类也在类路径中。
这样您就可以从命令行(可能不是您想要的)或直接在您的 java 程序中执行它们。
JUnitCore.runClasses(TestClass1,TestClass2,...)
关于java - 如何在java程序中运行外部测试用例(Class,junit)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1197882/