SpringBoot整合junit
主要分为4步
- 添加依赖
- 创建测试类
- 在测试类上添加注解
- 在测试类注入测试对象
1:导入依赖包
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency>
|
2:创建测试类

3:在测试类上添加注解并注入测试对象
测试类上注解:
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Springbootdemo1Application.class)
package com.offcn.springbootdemo1;
import com.offcn.springbootdemo1.mapper.UUserMapper; import com.offcn.springbootdemo1.pojo.UUser; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource; import java.util.List;
//添加整合junit注解 @RunWith(SpringRunner.class) @SpringBootTest(classes = Springbootdemo1Application.class) public class AppTest { //注入Mapper对象,用来获取List<UUser>集合 @Resource private UUserMapper userMapper; @Test public void TestMethod(){ List<UUser> uUsers = userMapper.selectUUser(); for (UUser uUser : uUsers) { System.out.println(uUser); } } }
|
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 字符编码:从基础到乱码解决
· 提示词工程——AI应用必不可少的技术