【四: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));
    }
}
相关推荐
野生程序员y2 分钟前
Spring DI/IOC核心原理详解
java·后端·spring
WAWA战士7 分钟前
mysql总结
数据库
熊思宇12 分钟前
Sqlite“无法加载 DLL“e_sqlite3”: 找不到指定的模块”解决方法
数据库·sqlite
往事随风去15 分钟前
面试官:mysql从数据库断开一段时间后,部分binlog已丢失,如何重建主从?
运维·数据库·mysql
J.Kuchiki19 分钟前
【PostgreSQL内核学习 —— (SeqScan算子)】
数据库·postgresql
酷酷的崽79841 分钟前
Redis 键(Key)的命令
数据库·redis·缓存
189228048611 小时前
NW622NW623美光固态闪存NW624NW635
大数据·网络·数据库·人工智能·microsoft·性能优化
云飞云共享云桌面1 小时前
1台电脑10个画图设计用怎么实现
linux·运维·服务器·网络·数据库·自动化·电脑
TTBIGDATA2 小时前
【Ambari监控】Ambari-Metrics 的分支研究
大数据·数据库·hadoop·ambari·bigtop·edp·hidataplus
Z_z在努力2 小时前
【杂类】应对 MySQL 处理短时间高并发的请求:缓存预热
数据库·mysql·缓存