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

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

相关推荐
go4it9 分钟前
聊聊spring-boot-autoconfigure的模块化
后端
陈果然DeepVersion16 分钟前
Java大厂面试真题:Spring Boot+Kafka+AI智能客服场景全流程解析(一)
spring boot·微服务·kafka·消息队列·java面试·rag·ai智能客服
鬼火儿33 分钟前
集成RabbitMQ+MQ常用操作
java·后端
Merrick1 小时前
Java 方法参数默认值新方案:使用DefArgs!
java·后端
IT_陈寒1 小时前
Python数据处理速度慢?5行代码让你的Pandas提速300% 🚀
前端·人工智能·后端
程序员小假1 小时前
finally 释放的是什么资源?
java·后端
技术砖家--Felix1 小时前
Spring Boot配置篇:详解application.properties和application.yml
java·spring boot·后端
用户21411832636021 小时前
Claude+Codex协同开发,让AI编程效率翻倍成本直降近半
后端
行思理1 小时前
IntelliJIdea 创建java spring boot程序
java·开发语言·spring boot
帧栈2 小时前
SpringBoot + iTextPDF + Acrobat 构建动态PDF表单的完整实践
spring boot·后端·pdf