Spring Boot集成单元测试调用dao,service

文章目录

  • [Spring Boot集成单元测试调用dao,service](#Spring Boot集成单元测试调用dao,service)
    • [1 添加相关依赖](#1 添加相关依赖)
    • [2 新建测试类](#2 新建测试类)

Spring Boot集成单元测试调用dao,service

1 添加相关依赖

xml 复制代码
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
    <exclusions>
        <exclusion>
            <groupId>org.junit.vintage</groupId>
            <artifactId>junit-vintage-engine</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.12</version>
    <scope>test</scope>
</dependency>

2 新建测试类

java 复制代码
import com.geekmice.staging.staging.BaoProjectApiApplication;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@SpringBootTest(classes=Application.class)
// Application 主启动类
public class JzrTest{
    
    @Autowired
    private UserDAO userdao;
    
    @Test
    //@Commit
    //@Transactional
    public void test(){
        System.out.println(userdao.select());    
    }
}

温馨提示:本人开发上线视频网站,有想要的看视频的,可以看看。小松鼠

相关推荐
gaoshan1234567891020 小时前
springboot 使用zip4j下载压缩包,压缩包内的数据来自oss文件管理服务器
java·服务器·spring boot
猹叉叉(学习版)20 小时前
【ASP.NET CORE】 12. DDD基本概念
笔记·后端·架构·c#·asp.net·.netcore
独断万古他化21 小时前
【抽奖系统开发实战】Spring Boot 项目的奖品模块开发:文件上传、时序设计与奖品创建
java·spring boot·后端·mvc·文件
饕餮争锋21 小时前
Supabase 简介
后端·开源
常利兵21 小时前
打造Spring Boot接口护盾:防重提交与限流秘籍
java·spring boot·后端
Hvitur21 小时前
解决报错:eclipse报错:LSP (Spring Boot Language Server)
spring boot·eclipse·里氏替换原则
晨非辰21 小时前
Makefile构建哲学:从依赖推导到自动化编译,掌握大型项目的构建逻辑,告别手动编译焦虑
linux·运维·服务器·c++·人工智能·后端·自动化
写代码的小阿帆21 小时前
SpringBoot项目部署——命令行、Nginx代理与docker容器
spring boot·nginx·docker
汽车仪器仪表相关领域21 小时前
全工况精准标定 + 智能安全防护,建筑机械防坠生命线:GZCVL T‑II 安全防坠器测试系统实战全解
功能测试·测试工具·安全·单元测试·汽车·压力测试·可用性测试
不能只会打代码21 小时前
基于Vue 3 + Spring Boot的物联网生鲜品储运系统设计与实现(源码附有详细的文档讲解)
java·前端·vue.js·spring boot·后端·物联网·github