【四: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));
    }
}
相关推荐
XiYang-DING4 分钟前
【Spring】 SpringBoot 配置文件
java·spring boot·spring
我是一颗柠檬10 分钟前
【MySQL全面教学】MySQL锁机制与并发控制Day10(2026年)
数据库·sql·mysql·database
代码中介商34 分钟前
B树:数据库索引的高效基石
数据结构·数据库
小马爱打代码35 分钟前
Spring源码 第七篇:Spring Boot 自动配置原理深度拆解
java·spring boot·spring
fen_fen35 分钟前
Oracle12,新增自增主键表和批量插入数据
数据库·sql·mysql
deepin_sir37 分钟前
11 - 模块与包
前端·数据库·python
念恒1230640 分钟前
MySQL索引
数据库·mysql
Lao A(zhou liang)的菜园42 分钟前
如何快速诊断Oracle性能问题?
数据库·oracle
铁皮哥1 小时前
【agent 开发】Claude Code 的 Skill 是怎么被加载的?从 name/description 到 SKILL.md 再到资源文件
java·服务器·数据库·python·gitee·github·软件工程
一只fish1 小时前
Oracle官方文档翻译《Database Concepts 26ai》第14章-物理存储结构
数据库·oracle