java - 如何在java程序中运行外部测试用例(Class,junit)?

标签 java junit

如何在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/

相关文章:

java - 面临 Spring AOP 中 Before 建议的问题

java - 在我的 Android 应用程序中集成 PagerSlidingTabStrip 时出错

java - 关闭项目后线程仍然退出,如何杀死它?

java - 在 java 反射中发送到 getDeclaredMethod(String, Class[]) 的参数类型

java - 如何验证 Java 卡上是否已安装小程序

java - 在最大尝试次数后,Testng RetryListener 未使测试用例失败

java - 我如何测试接口(interface)?

android - 如何使用 Android Studio 运行单元测试

java - 测试 Junit 和 Mockito 在分析日期和小时数时出现错误

junit - 错误 : java. lang.Exception: 没有可运行的方法