JUnit 5 单元测试框架

依赖安装

复制代码
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.13.2</version>
    <scope>test</scope>
</dependency>

所有支持的注解都在包 org.junit.jupiter.api 下。

基本使用:

java 复制代码
import org.junit.Assert;

import org.junit.Test;
import org.springframework.boot.test.context.SpringBootTest;

import javax.annotation.Resource;
import java.util.List;

@SpringBootTest
public class SampleTest {

    @Resource
    private UserMapper userMapper;

    @Test
    public void testSelect() {
        System.out.println(("----- selectAll method test ------"));
        List<User> userList = userMapper.selectList(null);
        Assert.assertEquals(5, userList.size());
        userList.forEach(System.out::println);
    }

}
相关推荐
難釋懷1 天前
OpenResty监听请求
junit·openresty
難釋懷1 天前
OpenResty获取参数的API
junit·openresty
難釋懷2 天前
OpenResty请求参数处理
junit·openresty
難釋懷2 天前
OpenResty获取参数并返回
junit·openresty
金銀銅鐵2 天前
[Java] 从 class 文件看 EasyMock 对 @Mock 注解的处理
后端·单元测试
Boop_wu2 天前
[Java EE 进阶] Spring Boot 日志全面解析 : 配置与实战
junit·java-ee·单元测试
网络安全-杰克2 天前
单元测试 Mock不Mock?
自动化测试·软件测试·单元测试
老神在在0013 天前
测试分类+自动化测试01
功能测试·学习·单元测试·postman
Lyyaoo.3 天前
适配器模式
单元测试·适配器模式
小陈工3 天前
2026年3月27日技术资讯洞察:量子计算密码突破、硬件安全新范式与三月网络安全警报
服务器·python·安全·web安全·单元测试·集成测试·量子计算