有没有办法知道测试案例中测试方法的数量?
Is there a way to know the number of test methods in a test case?
我要做的是有一个测试用例,它可以测试几种情况,而对于所有这些情况,我只会做一次数据setUp().同样,我想在所有测试方法结束时进行一次清理(tearDown()).
What I want to do is have a test case which tests several scenarios and for all these i would be doing the data setUp() only once. Similarly I would like to do the cleanup (tearDown()) once at the end of all the test methods.
我正在使用的当前方法是为文件中存在的测试方法的数量维护一个计数器,并在tearDown方法中将其递减,并在计数达到0时进行清理.但是需要使用此计数器无论何时添加新的测试方法,都是如此.
The current approach i am using is to maintain a counter for the number of test methods that are present in the file and decrement them in the tearDown method and do the cleanup when the count reaches 0. But this counter needs to be taken care of whenever new test methods are added.
推荐答案您可能应该使用带有 @ BeforeClass 和@AfterClass.
Instead of using setup/teardown you should probably use methods annotated with @BeforeClass and @AfterClass instead.
更多推荐
在JUnit TestCase中查找测试方法的数量
发布评论