前言
本文介绍了如何使用SpringBoot整合JUnit,其实只需要简单的两步就可以了.
一、JUnit是什么?
JUnit 是一个 Java 编程语言的单元测试框架。JUnit 在测试驱动的开发方面有很重要的发展,是起源于 JUnit 的一个统称为 xUnit 的单元测试框架之一。
二、整合步骤步骤
1.导入jar包
代码如下(示例):
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
</dependency>
2.测试类配置
我们只需要在创建的测试类上加上注解
@RunWith用于设定类运行器,SpringJUnit4ClassRunner.class是Spring整合JUnit的专用类运行器
@ContextConfiguration用于引入配置文件
接下来我们在方法上加上@Test,就可以直接进行测试了
我是本篇小编LXL
遇到Bug需要帮助,
欢迎加wx:
xmzl1988
备注"csdn博客“
温馨提示此为有偿服务;