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. 『动善时』JMeter基础 — 3、JMeter插件管理

    JMeter是一个Java开发的开源软件,开源的软件有一个好处,就是会有很多第三方开发出来的插件,使得JMeter在处理某一些功能的时候更加的方便.并且这些插件拿过来就可以使用,完全免费的. 我们安装 ...

  2. nginx 完美解决tp3.2.3 404问题

    最近我把Apache给换成nginx,当我把tp项目搬过去运行的时候发现404 错误 ,原来是因为nginx不支持 pathinfo 模式,需要自己配置 下面我配置 在server配置里面 locat ...

  3. 【MybatisPlus】使用Wrappers条件构造器构造or和and

    模糊查询中,会有针对一个数据,需要查询数据库的多个字段的情况,例如: 上图中的平台名称和平台进程在数据表中是两个不同的字段, 如果不使用Mybatisplus,仅使用Mybatis,则只有通过写xml ...

  4. thinkphp5安装php高版本出现No input file specified.解决

    <IfModule mod_rewrite.c> Options +FollowSymlinks -Multiviews RewriteEngine On RewriteCond %{RE ...

  5. drozer源码学习:app

    源码下载:https://github.com/mwrlabs/drozer:模块的源码位于src.drozer.modules,根据模块名来划分文件夹: app.auxiliary.exploit. ...

  6. POJ2391 Floyd+离散化+二分+DINIC

    题意:       有n个猪圈,每个猪圈里面都有一定数量的猪(可能大于当前猪圈的数量),每个猪圈都有自己的容量,猪圈与猪圈之间给出了距离,然后突然下雨了,问多久之后所有的猪都能进圈. 思路:     ...

  7. CVE-2010-3974:Windows 传真封面编辑器 FxsCover.exe 双重释放漏洞调试分析

    0x01 堆空间申请后的双重释放 Windows FxsCover 程序存储封面编辑器的信息,封面编辑器是传真服务的一个组件,通过解析特定的传真封面文件(.cov)时,会调用类析构函数对同一内存中的栈 ...

  8. 【python】Leetcode每日一题-森林中的兔子

    [python]Leetcode每日一题-森林中的兔子 [题目描述] 森林中,每个兔子都有颜色.其中一些兔子(可能是全部)告诉你还有多少其他的兔子和自己有相同的颜色.我们将这些回答放在 answers ...

  9. docker学习之使用 DockerFile 构建镜像并搭建 swarm+compose 集群

    题目要求 (1)将springboot应用程序打成jar包:Hot.jar (2)利用dockerfile将Hot.jar构建成镜像 (3)构建 Swarm 集群 (4)在 Swarm 集群中使用 c ...

  10. 腾讯云原生混合云-第三方集群弹EKS应对突发流量的利器

    作者 何鹏飞,腾讯云专家产品经理,曾作为容器私有云.TKEStack的产品经理兼架构师,参与腾讯云内部业务.外部客户容器化改造方案设计,目前负责云原生混合云产品方案设计工作. 胡晓亮,腾讯云专家工程师 ...