使用Java JUnit框架里的@SuiteClasses注解管理测试用例_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > 使用Java JUnit框架里的@SuiteClasses注解管理测试用例

使用Java JUnit框架里的@SuiteClasses注解管理测试用例

 2020/10/19 12:55:35  JerryWang_SAP  程序员俱乐部  我要评论(0)
  • 摘要:SupposeIhavefourtestcasesinmyproject,thetotalmethodstobetested:7BasedontheblogRunonlygivensetsofyourunittestvia@Category,itispossibletoorganizetestmethodswithinTHESAMECLASStodifferentcategoriesvia@Category,thatis
  • 标签:使用 测试 Java 注解 class

Suppose I have four test cases in my project, the total methods to be tested: 7

class="ztext-empty-paragraph" style="">?

?

Based on the blog?Run only given sets of your unit test via @Category, it is possible to organize test methods within THE SAME CLASS to different categories via @Category, that is, the granularity to control which test methods should be executed is method level.

There is another annotation @SuiteClasses which can allows us to categorize test classes into different test suites, and once we specify a given test suite to be executed, all test classes within that suite would be executed one by one.

For example, I create a suite TestSuite1and2 and only put first and second test case into it, so when this test suite is executed, only three test methods ( 1 from first test case and 2 from second test case ) are executed:

?

?

And the same logic for TestSuite2and3:

?

?

If you need to integrate test suite execution into Maven, add the following parts in pom.xml:

monospace; font-size: inherit; background-color: inherit;"><plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <includes>
                        <include>${runSuite}</include>
                    </includes>
                </configuration>
            </plugin>

Then use the following command line:

?

?

You will get exactly the same result as in Eclipse:

?

?

要获取更多Jerry的原创文章,请关注公众号"汪子熙":

发表评论
用户名: 匿名