利用Spring Boot配置的TestNG测试用例详解
来源:互联网 发布:属于网络教育的特征是 编辑:程序博客网 时间:2024/06/08 07:44
与JUnit不同,Spring Boot本身没有提供与TestNG集成的基础设施。
那么如何利用Spring Boot的配置,执行一个TestNG测试用例呢?在Spring Boot提供的大量samples中,有一个spring-boot-sample-testng可供参考。
基于该sample中,我们的TestNG测试类如下:
@SpringBootTest(classes = { ClientLauncher.class }, webEnvironment = WebEnvironment.DEFINED_PORT)@DirtiesContext(classMode = ClassMode.AFTER_CLASS)public class TestHealthCheckTestNGClient extends AbstractTestNGSpringContextTests { @Autowired private HealthCheckClient healthCheckClient; @Test public void getHealthCheckIntegrationTest(){ ResponseEntity<List<Health>> healthCheckResponse = healthCheckClient.getHealthCheck(); assert HttpStatus.OK.equals(healthCheckResponse.getStatusCode()); }}
注意,测试类继承了spring-test专为TestNG实现的AbstractTestNGSpringContextTests类。
对比JUnit测试用例如下:
@RunWith(SpringRunner.class)@SpringBootTest(classes = { ClientLauncher.class }, webEnvironment = WebEnvironment.DEFINED_PORT)@DirtiesContext(classMode = ClassMode.AFTER_CLASS)public class TestHealthCheckClient { @Autowired private HealthCheckClient healthCheckClient; @Test public void getHealthCheckIntegrationTest() throws Exception{ ResponseEntity<List<Health>> healthCheckResponse = healthCheckClient.getHealthCheck(); Assert.assertEquals(HttpStatus.OK, healthCheckResponse.getStatusCode()); }}
参考链接:
https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples/spring-boot-sample-testng
阅读全文
1 0
- 利用Spring Boot配置的TestNG测试用例详解
- 在Eclipse中开发使用Spring IOC的JUnit/TestNG测试用例之详解
- 在Eclipse中开发使用Spring IOC的JUnit/TestNG测试用例之详解
- Java Spring搭配TestNG测试配置
- TestNG测试用例的分组
- TestNG并发兼容性测试testng.xml文件的配置
- TestNG测试的并发执行详解
- testng集成spring测试
- spring集成TestNg测试
- Spring boot(2)-配置详解
- Spring boot(2)-配置详解
- Spring Boot日志配置详解
- TestNG的testng.xml实现多个测试用例的不同组合
- TestNG方法测试及注意要点 代码及配置详解(解决testng方法不执行问题)
- spring boot 单纯的使用cas client配置详解
- 配置一个Spring Boot应用的过程详解
- 解决TestNG测试用例依赖性的问题
- TestNG组织测试用例的最佳实践
- C++中了类继承和调用父类的构造函数方法
- Android系统启动流程总览
- Linux 技巧:让进程在后台可靠运行的几种方法
- ROC、AUC、K-S
- hdu4415 Assassin’s Creed
- 利用Spring Boot配置的TestNG测试用例详解
- (PAT乙)1002. 写出这个数
- 蚂蚁搬新家了_还在办公室搞了个音乐节
- 使用sendmail发送email
- winform 性能优化
- 补码的求法
- 解决硬盘挂载错误 重启失败问题
- 大数据风控模型靠谱吗?
- InnoDB和MYIASM区别