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

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

相关推荐
爷_13 分钟前
Golang: sqlc 和 goose 最佳实践
后端·go·全栈
万少1 小时前
我是如何使用 Trae IDE 完成《流碧卡片》项目的完整记录
前端·后端·ai编程
ituff1 小时前
微软认证考试又免费了
后端·python·flask
倔强的石头_1 小时前
openGauss赋能智能客服:AI时代的企业服务变革
后端
自不量力的A同学2 小时前
Spring Boot 4.0.0 正式发布
java·spring boot·后端
d***29242 小时前
【spring】Spring事件监听器ApplicationListener的使用与源码分析
java·后端·spring
v***5653 小时前
Spring Cloud Gateway 整合Spring Security
java·后端·spring
码事漫谈3 小时前
C++中不同类型的默认转换详解
后端
码事漫谈3 小时前
C++类型转换的隐蔽陷阱:当size_t遇见负数
后端