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

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

相关推荐
一点程序9 小时前
基于SpringBoot的选课调查系统
java·spring boot·后端·选课调查系统
奋进的芋圆10 小时前
Spring Boot 实现三模安全登录:微信扫码 + 手机号验证码 + 邮箱验证码
spring boot·redis·微信
怪兽源码11 小时前
基于SpringBoot的选课调查系统
java·spring boot·后端·选课调查系统
csdn_aspnet11 小时前
ASP.NET Core 中的依赖注入
后端·asp.net·di·.net core
昊坤说不出的梦12 小时前
【实战】监控上下文切换及其优化方案
java·后端
疯狂踩坑人12 小时前
【Python版 2026 从零学Langchain 1.x】(二)结构化输出和工具调用
后端·python·langchain
m0_7400437313 小时前
【无标题】
java·spring boot·spring·spring cloud·微服务
重整旗鼓~13 小时前
1.外卖项目介绍
spring boot
橘子师兄13 小时前
C++AI大模型接入SDK—ChatSDK封装
开发语言·c++·人工智能·后端
@ chen14 小时前
Spring事务 核心知识
java·后端·spring