在Junit 4中运行所有测试 [英] Run all tests in Junit 4
问题描述
我在Eclipse中尝试过New ... - > Test Suite选项,但这似乎只适用于JUnit 3,通过扩展从TestCase
测试类是JUnit 4,所以它们唯一的区别特征是注释,没有命名约定,没有TestCase的子类化。
提前感谢
虽然这并不能真正解决您的直接问题,创建套房和套房的有用的一般做法,例如对于一些类似于 PackageFooSuite
等的套件,再次将这些套件组合在一个或多个套件中,如 ModuleFooSuite
并具有一个顶级套件,如 AllTestsSuite
。这样一来,可以轻松运行所有测试,以及对我正在处理的软件包的子模块测试(并且测试运行速度比我总是运行所有测试的速度更快):
@RunWith(Suite.class)
@ Suite.SuiteClasses({PackageFooSuite.class,PackageBarSuite.class})
public final AllTestsSuite {} //或ModuleFooSuite,以及AllTests中的
I want to be able to run all tests in a project programmatically. I know Eclipse has a "Run as JUnit test" configuration which somehow grabs all the tests in a project and run them. Is there any way for me to also grab the list of tests programmatically and run them? Or is there some good way to construct a test suite containing all the test cases without manually listing out every one (all 700+) of them?
I've tried the "New... -> Test Suite" option in Eclipse, but that seems to work only for JUnit 3, identifying tests by their extending from TestCase
The test classes are JUnit 4, so their only distinguishing characteristic is the annotation, no naming convention, no subclassing from TestCase.
Thanks in advance!
Though it does not really solve your immediate problem, I find it a very useful general practice to create suites and suites of suites, e.g. for a package something like PackageFooSuite
etc. and assemble these suites in one or more suites again, like ModuleFooSuite
and have one top-level suite, like AllTestsSuite
. That way it's easy to run both all tests in one step as well as submodule tests for the package I'm currently working on (and have the tests run quicker than if I would always run all of them):
@RunWith(Suite.class)
@Suite.SuiteClasses({ PackageFooSuite.class, PackageBarSuite.class} )
public final class AllTestsSuite {} // or ModuleFooSuite, and that in AllTests
这篇关于在Junit 4中运行所有测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!