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

}
相关推荐
码农水水16 分钟前
阿里Java面试被问:单元测试的最佳实践
java·面试·单元测试
indexsunny1 小时前
互联网大厂Java面试实战:Spring Boot、微服务与Kafka在电商场景中的应用
java·spring boot·redis·junit·kafka·mockito·microservices
HashFlag1 天前
单元测试(go)
golang·单元测试
_200_2 天前
Lua 运算符
开发语言·junit·lua
_200_2 天前
Lua 基本数据类型
开发语言·junit·lua
卓码软件测评2 天前
第三方CNAS软件测试机构【Apifox Mock脚本进阶_使用JavaScript自定义响应逻辑】
测试工具·ci/cd·性能优化·单元测试·测试用例
㳺三才人子3 天前
初探 Spring Framework OncePerRequestFilter
spring boot·spring·junit
魏波.4 天前
如何衡量单元测试质量?
单元测试
Wang's Blog4 天前
Lua: 事件处理深度解析之从协程到跨平台架构实践
junit·架构·lua
阳光普照世界和平5 天前
2025年单元测试与软件质量工程领域研究现状与进展深度分析报告
单元测试