spring项目实现单元测试过程解析
更新时间:2019年10月31日 15:59:46 作者:不良帅~
这篇文章主要介绍了spring项目实现单元测试过程解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
后台开发过程中,写单元测试是非常重要的,对于我们开发人员调试、排查问题是很方便的,
但是我们在启动项目的时候,需要将所以类交给spring托管,在单元测试中需要怎么实现类的注入呢?
直接上图
继续上代码
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
<br data-filtered="filtered">@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={
"classpath:application-context.xml",
"classpath:application-database.xml",
"classpath:application-redis.xml"})
public class PartRelevanceTest {
@Resource
private PartRelevanceMapper partRelevanceMapper;
@Test
public void selectTypeNumOne() {
PartRelevanceTypeNum record = new PartRelevanceTypeNum();
record.setRelCode("2222112");
record.setType("2");
PartRelevanceTypeNum typeNum = partRelevanceMapper.selectTypeNumOne(record);
System.out.println(typeNum==null?"typeNum-数据为空":typeNum.toString());
}
}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
相关文章
Java 8 中 Map 骚操作之 merge() 的使用方法
本文简单介绍了一下Map.merge()的方法,除此之外,Java 8 中的HashMap实现方法使用了TreeNode和 红黑树,原理很相似,今天通过本文给大家介绍Java 8 中 Map 骚操作之 merge() 的用法 ,需要的朋友参考下吧2021-07-07
mybatis整合springboot报BindingException:Invalid bound stateme
这篇文章主要给大家介绍了关于mybatis整合springboot报BindingException:Invalid bound statement (not found)异常的解决办法,这个错误通常是由于Mapper文件中的statement id与Java代码中的方法名不一致导致的,需要的朋友可以参考下2024-01-01


最新评论