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

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

相关推荐
卷福同学4 小时前
不用服务器,不用配环境,我10分钟上线了一个AI Agent
人工智能·后端·算法
小明bishe187 小时前
计算机毕业设计之基于JAVA的植物科普网站
java·spring boot·spring·架构·课程设计
GetcharZp7 小时前
只需 10 分钟,轻松实现异地组网!Netmaker 保姆级部署教程来了
后端
前端兰博7 小时前
03-Spring Boot
后端
前端兰博7 小时前
01-Java开发基础语言
后端
前端兰博7 小时前
02-Servlet、JDBC、Maven、Mybatis
后端
咖啡八杯8 小时前
GoF设计模式——模板方法模式
java·后端·spring·设计模式
码事漫谈9 小时前
Loop 正在排斥人为操作
后端
爱勇宝9 小时前
办公资料反复修改、补传、交接混乱,我做了个桌面工具来解决这件事
前端·后端·程序员
万亿少女的梦1689 小时前
基于Python的高考志愿填报辅助系统设计与实现
java·spring boot·python·mysql·vue