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

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

相关推荐
QX_hao20 分钟前
【Go】--map和struct数据类型
开发语言·后端·golang
MC丶科1 小时前
【SpringBoot 快速上手实战系列】5 分钟用 Spring Boot 搭建一个用户管理系统(含前后端分离)!新手也能一次跑通!
java·vue.js·spring boot·后端
G探险者1 小时前
为何一个系统上线要经过N轮测试?带你看懂企业级发布体系
后端
lang201509283 小时前
Spring Boot 入门:5分钟搭建Hello World
java·spring boot·后端
Javashop_jjj4 小时前
三勾软件| 用SpringBoot+Element-UI+UniApp+Redis+MySQL打造的点餐连锁系统
spring boot·ui·uni-app
间彧4 小时前
Windows Server,如何使用WSFC+nginx实现集群故障转移
后端
间彧4 小时前
Nginx + Keepalived 实现高可用集群(Linux下)
后端
间彧4 小时前
在Kubernetes中如何部署高可用的Nginx Ingress Controller?
后端
间彧4 小时前
Ribbon负载均衡器和Nginx负载均衡器有什么区别
后端