【四:Spring整合Junit】

目录

相同点

前面都一样和Spring整合mybatis(基于注解形式)一样
Spring整合Mybatis

不同点
1、导入依赖增加
xml 复制代码
        <!-- 单元测试 -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>


        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>5.2.10.RELEASE</version>
        </dependency>
2、编写的位置不同。。路径一定要与实现类一致
java 复制代码
package com.xiong.service;

import com.xiong.config.SpringConfig;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = SpringConfig.class)
public class AccountServiceTest {

    @Autowired
    private AccountService accountService;

    @Test
    public  void  testFindById(){
        System.out.println(accountService.findById(1));
    }
}
相关推荐
猫猫不是喵喵.14 分钟前
从0到1创建一个微服务项目
java·数据库·微服务·1024程序员节
lsc_blog1 小时前
听到优化风声,先准备能由自己掌控的事
数据库·分布式·中间件·职场和发展·重构
墨痕诉清风2 小时前
SSRF漏洞实战记录+OSS桶命令执行+MCP漏洞
linux·服务器·数据库
Ashe8134 小时前
MySQL 慢日志先别急着加索引:三个指标能拦掉大半误判
数据库
瑞雪兆丰年兮5 小时前
JavaWeb-day14-SpringBootWeb原理篇
java·开发语言·spring boot·spring·bean·mybatis·javaweb
ClouGence5 小时前
最基础的异构数据库 DDL 同步,我们踩过哪些坑?
数据库·mysql·postgresql
羑悻的小杀马特6 小时前
Redis持久化三剑客:RDB二进制快照、AOF文本日志、混合模式如何守护你的数据安全?
数据库·redis·缓存·aof·持久化存储·rdb
小呆爱发呆6 小时前
第三章 MySQL 库表操作
数据库·mysql·adb
时间的拾荒人7 小时前
Redis 进阶实战:渐进式遍历、持久化机制与事务详解
数据库·redis·缓存