找到一个JUnit测试类的测试方法的数 [英] Finding the number of test methods in a JUnit test class

查看:156
本文介绍了找到一个JUnit测试类的测试方法的数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能得到一个JUnit测试类共测试方法的数量?

How I can get the number of total test methods in a JUnit test class?

存在一个类似<一href="http://stackoverflow.com/questions/535929/to-find-the-number-of-test-methods-in-a-junit-testcase">question这对JUnit4。当我使用JUnit3,有没有办法在得到的测试方法有多少?

There exists a similar question which was for JUnit4. As I am using JUnit3, is there any way in junit3 to get the number of test methods?

当运行的junit测试项目,JUnit的窗口通常显示的顶部方法的总数。这意味着它计数的测试方法本身的数目。是否有可能从它那里得到?

While running the junit test project, JUnit window usually shows the total number of methods on the top. That means it counts the number of test methods itself. Is it possible to get from it?

推荐答案

您可以使用反射。

类Java有方法的getMethods(),你可以用它来获取所有的方法给定的类(这将是你的JUnit类)。

The Class class in Java has the method getMethods() which you can use to get all the methods for the given class (which will be your JUnit class).

然后为每个方法,你应该检查,如果它是一个测试方法(IIRC在JUnit3的测试方法是那些以测试)

Then for each method you should check if it's a test method (IIRC the test methods in JUnit3 are those that start with "test")

这篇关于找到一个JUnit测试类的测试方法的数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆