找到一个JUnit测试类的测试方法的数测试、方法、JUnit

由网友(鬼娃╮)分享简介:我怎样才能得到一个JUnit测试类共测试方法的数量? How I can get the number of total test methods in a JUnit test class? 存在一个类似question这对JUnit4。当我使用JUnit3,有没有办法在 junit3 得到的测试方法有多少?T...

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

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

存在一个类似question这对JUnit4。当我使用JUnit3,有没有办法在 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")

阅读全文

相关推荐

最新文章