Junit测试 - Spring的配置
第一种:
@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的配置的更多相关文章
- Junit 测试 Spring
在测试类上加上@RunWith,和@ContextConfiguration @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration ...
- Junit测试Spring应用Dubbo测试框架之-Excel 工具类
package com.tree.autotest.demo; import com.alibaba.fastjson.JSON;import org.apache.poi.hssf.usermode ...
- spring boot web开发 简单的增删改查和spring boot 自带的Junit测试 案例
创建 web项目 配置pom.xml文件 ------相当于jar包 配置application.yml -----配置文件(spring数据库连接.server服务.logging日志等) 创建 ...
- Spring Boot 解决方案 - JUnit 测试
简单的 JUnit 项目 回顾一下创建并运行简单的 JUnit 测试项目,先添加 JUnit 依赖然后编写类似如下模板的测试类,使用 IDE 的话直接用插件运行就行, 使用 Maven 的话运行命令 ...
- Spring学习笔记(二)——Spring相关配置&属性注入&Junit整合
一.Spring的相关配置 1.1 Bean元素 class属性:被管理对象的完整类名 name属性:给Bean起个名字,能重复,能使用特殊字符.后来属性 id属性:给Bean起个名字,不能重复,不能 ...
- Spring之junit测试集成
简介 Spring提供spring-test-5.2.1.RELEASE.jar 可以整合junit. 优势:可以简化测试代码(不需要手动创建上下文,即手动创建spring容器) 使用spring和j ...
- spring boot(三)Junit 测试controller
Junit测试Controller(MockMVC使用),传输@RequestBody数据解决办法 一.单元测试的目的 简单来说就是在我们增加或者改动一些代码以后对所有逻辑的一个检测,尤其是在我们后期 ...
- Struts2+Spring+Mybatis+Junit 测试
Struts2+Spring+Mybatis+Junit 测试 博客分类: HtmlUnit Junit Spring 测试 Mybatis package com.action.kioskmoni ...
- 无废话Android之android下junit测试框架配置、保存文件到手机内存、android下文件访问的权限、保存文件到SD卡、获取SD卡大小、使用SharedPreferences进行数据存储、使用Pull解析器操作XML文件、android下操作sqlite数据库和事务(2)
1.android下junit测试框架配置 单元测试需要在手机中进行安装测试 (1).在清单文件中manifest节点下配置如下节点 <instrumentation android:name= ...
随机推荐
- GenomicRangeQuery /codility/ preFix sums
首先上题目: A DNA sequence can be represented as a string consisting of the letters A, C, G and T, which ...
- thinkphp3.2跨控制器调用其他模块的方法
thinphp中前台后台都有互相调用方法,这样可以省去重复内容. 1 2 $hello = new \Admin\Common\Fun\hello(); $hello->hehe(); 调用其他 ...
- 解决Xftp经常断开连接的问题,Xftp中文乱码
#文件 --> 选项 --> 勾选“发送保持活动状态消息” 间隔 60秒 #工具 -> 选项 延伸阅读: Xshell个性化设置,解决Xshell遇到中文显示乱码的问题
- 第2月第24天 coretext 行高
1.NSMutableAttributedString 行高 NSMutableAttributedString *attributedString = [[NSMutableAttributedSt ...
- 我爱模仿app之格瓦拉客户端
最近有很多人问我,这个效果该怎么实现,那个功能该怎么实现.所以我准备开个专题,找一些app模仿,写一些示例代码,以供大家参考. 第一个下手的就是格瓦拉,没用过的可以下载看看,效果做的还是可以的,专场, ...
- ServletConfig 可以做啥
1.获得 servlet配置的servletname 2.获得servlet 配置的 getInitParameter("keyname") 3.获得servlet配置的 所有的 ...
- Java实现JDBC连接数据库实例
import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sq ...
- sqlserver查询效率
很多人不知道SQL语句在SQL SERVER中是如何执行的,他们担心自己所写的SQL语句会被SQL SERVER误解.比如: select * from table1 where name='zhan ...
- upload&&download
package am.demo; import java.io.File; import java.io.IOException; import java.util.Iterator; imp ...
- iOS 归档archive使用方法
归档是一种很常用的文件储存方法,几乎任何类型的对象都能够被归档储存,文件将被保存成自定 义类型的文件,相对于NSUserDefault具有更好的保密性. 1.使用archiveRootObject ...