Springboot单元测试@RunWith注解
2024-09-04 09:31:18
1.RunWith 注解
RunWith 就是一个运行器
可以在单元测试的时候,自动创建spring的应用上下文
2.正确使用
pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</exclusion>
<exclusion>
<artifactId>log4j-api</artifactId>
<groupId>org.apache.logging.log4j</groupId>
</exclusion>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-to-slf4j</artifactId>
</exclusion>
</exclusions>
</dependency>
3.测试用例
@RunWith(SpringRunner.class)
@SpringBootTest
public class RdsTest {
private static final Logger LOG = LoggerFactory.getLogger(RdsTest.class);
@Resource
RdsClientHolder rdsClientHolder;
@Resource
RdsInstanceTypesMapper rdsInstanceTypesMapper;
/**
* 查询状态
*/
@Test
public void describeRds(){
RdsClient rdsClient = rdsClientHolder.getClientByPinAlias("tech_prod");
DescribeInstanceAttributesRequest request = new DescribeInstanceAttributesRequest();
request.setRegionId("cn-north-1");
request.setInstanceId("mysql-b706i2vpmt");
DescribeInstanceAttributesResponse describeResponse = rdsClient.describeInstanceAttributes(request);
LOG.info("describeResponse : {}",JsonUtils.toJSONString(describeResponse.getResult(), true));
}
}
最新文章
- .NET正则表达式基础入门(四)
- 微信小程序社区上线
- 一次 Oracle 算出运算溢出问题 排查解决 (并非除数为零!)
- AngularJS Best Practices: ng-include vs directive
- css左右居中的几种常见方法
- 10. 求N分之一序列前N项和
- HDOJ-ACM1097(JAVA) A hard puzzle
- iOS中保证线程安全的几种方式与性能对比
- border做箭头的例子
- 【Android 应用开发】对Android体系结构的理解--后续会补充
- H5、C3、ES6的新特性
- QPushButton class
- Pycharm问题:module &#39;pip&#39; has no attribute &#39;main&#39;
- javascript基础 之 void
- Vue小案例 之 商品管理------修改商品数量以及增加入库日期属性
- code vs 2639 约会计划
- 2018/03/11 每日一个Linux命令 之 top
- adb 安装软件
- 搭建 ssm 环境
- 多网卡绑定(bond)