使用Java JUnit框架里的@SuiteClasses注解管理测试用例
Suppose I have four test cases in my project, the total methods to be tested: 7
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:
<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:
本文来自云栖社区合作伙伴“汪子熙”,了解相关信息可以关注微信公众号"汪子熙"。
低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
Java JUnit框架里@Category注解的工作原理
Suppose you have a large number of unit test cases and you don’t want them to be executed all at the same time during Maven build. You can simply achieve it via annotation @Category. (1) Create empty class FastTests and SlowTests.(2) In your test case class, categorize your test method using @Category annotation: (3) Append the following code to your pom.xml: <profiles> <profile> <id>SlowTests</id> <properties> <testcase.groups>com.sap.SlowTests</testcase.g...
- 下一篇
使用Java JUnit框架里的@Rule注解的用法举例
Suppose you need to repeatedly execute some test method in your unit test case, for example, you would like to test getPrice based on the first set of test data 5 times in test method test1() while for the second set of test data, only one time should be executed. The below class RepeatDemoOne is a bad example, where this special LOOP operation is mixed with test method implementation. Ideally the test method should only contain the pure logic to operate on the method being tested. So we have a ...
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
推荐阅读
最新文章
- SpringBoot2整合MyBatis,连接MySql数据库做增删改查操作
- CentOS8,CentOS7,CentOS6编译安装Redis5.0.7
- 设置Eclipse缩进为4个空格,增强代码规范
- CentOS8安装Docker,最新的服务器搭配容器使用
- Docker使用Oracle官方镜像安装(12C,18C,19C)
- CentOS8编译安装MySQL8.0.19
- SpringBoot2整合Redis,开启缓存,提高访问速度
- SpringBoot2配置默认Tomcat设置,开启更多高级功能
- Hadoop3单机部署,实现最简伪集群
- CentOS7,CentOS8安装Elasticsearch6.8.6