简体   繁体   English

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

[英]Finding the number of test methods in a JUnit test class

How I can get the number of total test methods in a JUnit test class? 如何获得JUnit测试类中的总数测试方法?

There exists a similar question which was for JUnit4. 对于JUnit4,存在类似的问题 As I am using JUnit3, is there any way in to get the number of test methods? 由于我使用JUnit3,有没有以任何方式获得的测试方法有多少?

While running the junit test project, JUnit window usually shows the total number of methods on the top. 在运行junit测试项目时,“ JUnit”窗口通常在顶部显示方法总数。 That means it counts the number of test methods itself. 这意味着它将计算测试方法本身的数量。 Is it possible to get from it? 有可能从中得到好处吗?

You can use reflection. 您可以使用反射。

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). Java中的Class类具有方法getMethods() ,您可以使用该方法获取给定类(将是您的JUnit类)的所有方法。

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") 然后,对于每种方法,您应该检查它是否是一种测试方法(IIRC,JUnit3中的测试方法是以“ test”开头的那些方法)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM