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

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

相关推荐
BS30813_vx27 分钟前
基于 Express + uni-app 的养老院管理系统设计与实现
后端·uni-app·express
明月_清风38 分钟前
DeepSeek Harness 安全审计实录:四个 PoC 揭露的 Agent 运行时"信任危机"
后端·安全·agent
苏三说技术1 小时前
再见了EasyExcel,我决定用Apache Fesod
后端
XR1234567881 小时前
医院移动医护零漫游无线网络选型指南
java·后端·struts
慧一居士1 小时前
Mybatis Plus中 LambdaQueryWrapper、QueryWrapper 区别对比
spring boot
干到60岁退休的码农1 小时前
13.构建登录接口响应数据
java·spring boot·mybatis
水巷石子1 小时前
学习langChain4j的第二天,体验springBoot中的starter
java·spring boot·学习·spring·langchain4j
ly76891 小时前
Spring Bean生命周期全流程:从BeanDefinition到销毁
java·后端·spring·bean生命周期·beandefinition·初始化回调
leeyi2 小时前
在 Go 里跑不信任的代码:WASM 沙箱的四道墙(第107篇)
后端
摇滚侠2 小时前
《Spring Boot 3:高级与架构设计》第 1 章 BeanDefinitionRegistry 阅读笔记 3
spring boot·笔记·后端