我有junit.framework.TestCase类的多个实例,其中包含各种测试用例。我想编写一个从这些实例运行特定测试用例的程序。

有没有一种方法可以动态调用junit测试,类似于java.lang.reflect API中的invoke()方法?

最佳答案

由于尚不清楚您要实现什么目标。在下面找到一些更一般的可能性。如果您使用的是Maven,则可以


运行特定的测试


(有关更多示例/可能性,请参见maven-surefire-plugin: single-test

mvn -Dtest=YourClass* test



为特定的JUnit类别注释类


(有关更多示例/可能性,请参见maven-surefire-plugin: JUnit_Categories

mvn test -Dgroups="your.test.group.Example"


编辑对于ivy,此SO帖子how-to-run-all-junit-tests-in-a-category-suite-with-ant可能有助于解决您的要求。

10-08 08:14
查看更多