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));
}
}

Springboot单元测试@RunWith注解的更多相关文章

  1. Springboot测试类之@RunWith注解

    @runWith注解作用: --@RunWith就是一个运行器 --@RunWith(JUnit4.class)就是指用JUnit4来运行 --@RunWith(SpringJUnit4ClassRu ...

  2. 五、springboot单元测试

    1.为什么要写测试用例 1. 可以避免测试点的遗漏,为了更好的进行测试,可以提高测试效率 2. 可以自动测试,可以在项目打包前进行测试校验 3. 可以及时发现因为修改代码导致新的问题的出现,并及时解决 ...

  3. Springboot单元测试Junit深度实践

    Springboot单元测试Junit深度实践 前言 单元测试的好处估计大家也都知道了,但是大家可以发现在国内IT公司中真正推行单测的很少很少,一些大厂大部分也只是在核心产品推广单测来保障质量,今天这 ...

  4. 使用RunWith注解改变JUnit的默认执行类,并实现自已的Listener

    使用RunWith注解改变JUnit的默认执行类,并实现自已的Listener在平时的单元测试,如果不使用RunWith注解,那么JUnit将会采用默认的执行类Suite执行,如下类: public  ...

  5. SpringBoot(15)—@Conditional注解

    SpringBoot(15)-@Conditional注解 作用 @Conditional是Spring4新提供的注解,它的作用是按照一定的条件进行判断,满足条件的才给容器注册Bean. 一.概述 1 ...

  6. springboot基础、注解等

    SpringBoot 1.springboot概念 Spring Boot是用来简化新Spring应用的初始搭建以及开发过程.该框架使用了特定的方式来进行配置,从而使开发人员不再需要定义样板化的配置. ...

  7. springmvc,springboot单元测试配置

    1. springmvc单元测试配置 <dependency> <groupId>junit</groupId> <artifactId>junit&l ...

  8. springboot单元测试为什么排除junit-vintage-engine

    https://blog.csdn.net/Ber_Bai/article/details/117001443 如果不排除,就需要使用@RunWith注解? 25-springboot整合单元测试指定 ...

  9. springboot整合mybaits注解开发

    springboot整合mybaits注解开发时,返回json或者map对象时,如果一个字段的value为空,需要更改springboot的配置文件 mybatis: configuration: c ...

随机推荐

  1. Java集合知识总结

    集合概述 集合:集合是Java中提供的一种容器,可以用来存储多个数据. 集合和数组的区别: (1)数组长度的是固定的,集合的长度是可变的. (2)数组中存储的都是同一类型的元素.集合存储的都是对象,对 ...

  2. android apk壳

    壳对于有过pc端加解密经验的同学来说并不陌生,android世界中的壳也是相同的存在.看下图(exe = dex):    概念清楚罗,我们就说下:壳最本质的功能就是实现加载器.你看加壳后,系统是先执 ...

  3. Python脚本暴力破解SSH口令以及构建僵尸网络(pxssh)

    目录 暴力破解SSH口令 SSH远端执行命令 构建僵尸网络 环境:Kali Linux  python 2.7.13 暴力破解SSH口令 Pxssh是pexpect库的ssh专用脚本,他能用预先写好的 ...

  4. 路由协议之OSPF

    目录 OSPF协议 OSPF的七种状态 OSPF的11种LSA Stub和Nssa OSPF中的防环机制 OSPF中的路由汇总和路由过滤 OSPF中的虚拟链路 虚拟链路有两种存在的意义 OSPF中的认 ...

  5. Winrar漏洞复现(CVE-2018-20250)

    本文讲的是Winrar漏洞利用脚本的使用方法,至于Winrar漏洞的原理,请移步--> Winrar目录穿越漏洞复现 本次利用脚本出处--> https://github.com/back ...

  6. 分子动力学模拟软件VMD的安装与使用

    技术背景 在分子动力学模拟过程中会遇到一些拓扑结构非常复杂的分子模型,所谓的复杂不仅仅是包含众多的原子,还有各种原子之间的成键关系与成键类型等.这时候就非常能够体现一个好的可视化软件的重要性了,这里我 ...

  7. liunx中文件夹不能删除怎么操作

    1.运行rm -rf 文件名称 2.不能删除对应文件并且提示"rm: cannot remove './.user.ini': Operation not permitted" 操 ...

  8. 使用C#进行数据库增删改查ADO.NET(一)

    这节讲一下如何使用C#进行数据库的增删改查操作,本节以SQL Server数据库为例. .NET 平台,使用ADO.NET 作为与数据库服务器的桥梁,我们通过ADO.NET就可以使用C#语言操作数据库 ...

  9. grub救援模式

    http://www.jinbuguo.com/linux/grub.cfg.html

  10. [Java] HOW2J(Java初级)

    变量 基本类型:整型(byte.short.int.long).字符型(char).浮点型(float.double).布尔型(boolean) 给基本类型赋值的方式叫字面值 字符的字面值放在单引号中 ...