SpringTest框架整合JUnit单元测试两种方式
来源:互联网 发布:mac os 显示内容放大 编辑:程序博客网 时间:2024/06/05 11:39
方式一:
JUnit单元测试中使用Spring框架
/** * <p>Title: com.edi.test.controller</p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2017</p> * <p>Company: www.blog.csdn.net/wanzuwodou<;/p> * 测试类 * @author joed * @version 1.0 * @date 2017/6/16 9:55 */@RunWith(SpringJUnit4ClassRunner.class)@ContextConfiguration(locations = {"classpath:/spring/applicationContext.xml"}, loader = GenericXmlContextLoader.class)public class BeanTest {
然后就可以直接将我们需要注入的内容注入:
例如:
public class BeanTest { @Resource private RestLogService restLogService; .........
方式二:
使用spring提供的整合Junit的基类
/** * <p>Title: com.edi.test.controller</p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2017</p> * <p>Company: www.blog.csdn.net/wanzuwodou<;/p> * * @author joed * @version 1.0 * @date 2017/7/6 10:37 */@ContextConfiguration(locations = {"classpath:/spring/applicationContext.xml"}, loader = GenericXmlContextLoader.class)public class JunitTest extends AbstractJUnit4SpringContextTests { @Autowired private AppUserTypeHandler appUserTypeHandler; @Test public void test123(){ AppUserType joed= appUserTypeHandler.findBySysCodeAndSysUserType("joed", "4"); if(null!=joed){ System.out.println(joed.getId()); } }}
阅读全文
0 0
- SpringTest框架整合JUnit单元测试两种方式
- 单元测试代码:SpringTest+JUnit
- 单元测试代码:SpringTest+JUnit
- Spring框架整合Junit单元测试框架的纯注解方式
- SpringTest框架JUnit单元测试用例获取ApplicationContext实例的方法
- SpringTest框架JUnit单元测试用例获取ApplicationContext实例的方法
- SpringTest框架JUnit单元测试用例获取ApplicationContext实例的方法
- Spring框架整合Junit单元测试框架
- Spring整合Junit框架进行单元测试Demo
- springtest整合junit并结合logback打印mybatis执行详细信息
- spring整合junit单元测试
- spring整合JUnit单元测试
- junit做单元测试的两种方法
- Spring整合JUnit框架进行单元测试代码使用详解
- Spring整合JUnit框架进行单元测试代码使用详解
- Spring整合JUnit框架进行单元测试代码使用详解
- Spring整合JUnit框架进行单元测试代码使用详解
- Junit单元测试框架详解
- s5pv210——LCD的原理和实战
- LinuxC语言实现下载功能(curl)
- Android中调用第三方打开本地doc、pdf、ppt、text等文件功能的实现
- QT 剪贴板 QClipboard 打开文件夹 openUrl
- Codeforces 600E Lomsat gelral 树上启发式合并
- SpringTest框架整合JUnit单元测试两种方式
- solution of my error
- Win10 时间与Internet时间同步超时
- 简单验证码
- Linux启动tomcat带控制台
- 日期处理(Date类 Calendar类)
- 两个乒乓球队进行比赛,各出三人。甲队为a,b,c三人,乙队为x,y,z三人。已抽签决定比赛名单。有人向队员打听比赛的名单。a说他不和x比,c说他不和x,z比,请编程序找出三队赛手的名单。
- AndroidStudio一次打多个包
- 2 秒杀系统模拟基础实现,使用Redis实现