spring 单元测试
来源:互联网 发布:深入理解大数据 黄宜华 编辑:程序博客网 时间:2024/05/14 09:45
在spring mvc 框架下。
1.引入junit4 和 spring-test 的架包 。
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.1.1.RELEASE</version>
</dependency>
2.1 使用自动注入:
@ContextConfiguration(locations = {"classpath:spring-jdbc.xml","classpath:applicationContext.xml"})
@RunWith(SpringJUnit4ClassRunner.class)
public class MyTest extends AbstractTransactionalJUnit4SpringContextTests{
@Autowired
AmmsDomainService ammsService;
@Test
public void Ammstest()
{
CacheMerchant cacheMerchant= ammsService.queryCacheMerchantAllByPosMerchant("827000058130091", "00007113");
System.out.println("通过posMid, TID 查询===="+cacheMerchant);
}
}
2.2手动加载spring的配置文件,并启动spring容器
public class MyTest extends AbstractTransactionalJUnit4SpringContextTests{
public void Ammstest()
{
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
context.start();
CacheMerchant cacheMerchant= ammsService.queryCacheMerchantAllByPosMerchant("827000058130091", "00007113");
System.out.println("通过posMid, TID 查询===="+cacheMerchant);
}
3.run as juniTest 就可以啦
- Spring单元测试
- Spring单元测试
- spring单元测试
- spring单元测试
- spring单元测试
- Spring单元测试
- spring 单元测试
- Spring单元测试
- spring单元测试
- spring 单元测试
- Spring单元测试
- spring 单元测试
- Spring单元测试
- spring 单元测试
- spring 单元测试
- spring单元测试
- Spring 单元测试
- Spring单元测试
- Joda-Time
- 大文件的多线程断点下载
- iOS如何上传代码到Github
- 在ARM Linux下使用GPIO模拟SPI时序详解
- java课程体系mybaties的学习
- spring 单元测试
- 最小量级的block块代码
- 文件的上传
- 如何用shell脚本编译java工程
- 缓存的概念
- 进制转换
- mysql数据库root密码忘记的修改方法
- poj Sliding Window
- 简单介绍ASI框架的使用