在JUnit TestCase中查找测试方法的数量

编程入门 行业动态 更新时间:2024-10-25 18:30:40
本文介绍了在JUnit TestCase中查找测试方法的数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

有没有办法知道测试案例中测试方法的数量?

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中查找测试方法的数量

本文发布于:2023-11-05 09:44:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1560507.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数量   测试   方法   JUnit   TestCase

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!