第一种:

@ContextConfiguration(locations = {"classpath*:/spring-core.xml"})
public class UserMapperTest extends AbstractJUnit4SpringContextTests { @Resource
private UserMapper userMapper; @Test
public void testQueryAllUser () {
User user = userMapper.queryById("1"); System.out.println(user.getName());
}
}

第二种:

public class UserMapperTest2 {

    private UserMapper userMapper;

    @Before
public void init(){
ApplicationContext ctx = new FileSystemXmlApplicationContext("classpath*:/spring/applicationContext.xml");
userMapper = (UserMapper)ctx.getBean("userMapper");
} public UserMapper getUserMapper() {
return userMapper;
} public void setUserMapper(UserMapper userMapper) {
this.userMapper = userMapper;
} }

UserMapper需要加注解:

/**
* 用户信息数据持久化操作接口
*/
@Repository
public interface UserMapper extends BaseMapper<User>

IT技术和行业交流群 417691667

Junit测试 - Spring的配置的更多相关文章

  1. Junit 测试 Spring

    在测试类上加上@RunWith,和@ContextConfiguration @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration ...

  2. Junit测试Spring应用Dubbo测试框架之-Excel 工具类

    package com.tree.autotest.demo; import com.alibaba.fastjson.JSON;import org.apache.poi.hssf.usermode ...

  3. spring boot web开发 简单的增删改查和spring boot 自带的Junit测试 案例

    创建 web项目 配置pom.xml文件   ------相当于jar包 配置application.yml -----配置文件(spring数据库连接.server服务.logging日志等) 创建 ...

  4. Spring Boot 解决方案 - JUnit 测试

    简单的 JUnit 项目 回顾一下创建并运行简单的 JUnit 测试项目,先添加 JUnit 依赖然后编写类似如下模板的测试类,使用 IDE 的话直接用插件运行就行, 使用 Maven 的话运行命令 ...

  5. Spring学习笔记(二)——Spring相关配置&属性注入&Junit整合

    一.Spring的相关配置 1.1 Bean元素 class属性:被管理对象的完整类名 name属性:给Bean起个名字,能重复,能使用特殊字符.后来属性 id属性:给Bean起个名字,不能重复,不能 ...

  6. Spring之junit测试集成

    简介 Spring提供spring-test-5.2.1.RELEASE.jar 可以整合junit. 优势:可以简化测试代码(不需要手动创建上下文,即手动创建spring容器) 使用spring和j ...

  7. spring boot(三)Junit 测试controller

    Junit测试Controller(MockMVC使用),传输@RequestBody数据解决办法 一.单元测试的目的 简单来说就是在我们增加或者改动一些代码以后对所有逻辑的一个检测,尤其是在我们后期 ...

  8. Struts2+Spring+Mybatis+Junit 测试

    Struts2+Spring+Mybatis+Junit 测试 博客分类: HtmlUnit Junit Spring 测试 Mybatis  package com.action.kioskmoni ...

  9. 无废话Android之android下junit测试框架配置、保存文件到手机内存、android下文件访问的权限、保存文件到SD卡、获取SD卡大小、使用SharedPreferences进行数据存储、使用Pull解析器操作XML文件、android下操作sqlite数据库和事务(2)

    1.android下junit测试框架配置 单元测试需要在手机中进行安装测试 (1).在清单文件中manifest节点下配置如下节点 <instrumentation android:name= ...

随机推荐

  1. storyboard连线容易出现的问题

    - 连接的方法代码被删掉,但是连线没有去掉 - 可能会出现方法找不到错误 - unrecognized selector sent to instance- 连接的属性代码被删掉,但是连线没有去掉 - ...

  2. MySQL show processlist命令详解

    show processlist; 命令的输出结果显示了有哪些线程在运行,可以帮助识别出有问题的查询语句,两种方式使用这个命令. 方式1:进入mysql/bin目录下输入mysqladmin proc ...

  3. 4. K线基础知识

    1. K线基础知识 K线又叫阴阳线.蜡烛图.最早由日本米市商人发明,后来推广应用到金融行情价格的分析. K线图的构造主要包含四个价格因素:开盘价.收盘价.最高价.最低价 2. K线图例 收盘价高于开盘 ...

  4. 配置ngnix

    server { listen ; server_name www.aaa.com; root /home/www/...; index index.php index.html index.htm; ...

  5. C# 文件/文件夹重命名

    C# 重命名的方法是MoveTo() 官方文档地址 (https://msdn.microsoft.com/zh-cn/library/system.io.fileinfo.moveto%28VS.8 ...

  6. POJ 1860(spfa)

    http://poj.org/problem?id=1860 题意:汇率转换,与之前的2240有点类似,不同的是那个题它去换钱的时候,是不需要手续费的,这个题是需要手续费的,这是个很大的不同. 思路: ...

  7. 如何有效地描述软件缺陷(Defect)?

    最近一个月偷懒了,刚看到一篇博文很不错.最近也是碰到一样的问题,由于我记录bug的描述不够清晰.导致开发看不懂我描述的bug,还有一些配置信息没记录好.出现一问三不知的情况,还被领导训.下面的博文是来 ...

  8. ABAP 客户报表

    *&---------------------------------------------------------------------* *& Report  ZSDR014 ...

  9. CentOS7 词典

    goldendict sudo yum install goldendict打开goldendict,阅读welcome,添加本地词典,在http://abloz.com/huzheng/stardi ...

  10. 响应式字体(js控制)

    window.onload=function(x){if ('addEventListener' in document) {document.addEventListener('DOMContent ...