首页 > 编程语言 > 详细

idea下maven项目下spring junit 测试用例

时间:2017-08-03 20:58:31      阅读:261      评论:0      收藏:0      [点我收藏+]
使用idea在编写的类下右键Go->Test或者ctrl+shift+t,点击create new test会在相应目录下创建test类
别写代码如下
@RunWith(value = SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:/config/**/applicationContext*.xml" }, loader = GenericXmlContextLoader.class)
@Transactional
public class BaseImageTextInfoActionTest extends AbstractCommonAction {
    @Autowired
    private BaseImageTextInfoService baseImageTextInfoService;

    @Test
    public void queryById() throws Exception {
      //具体代码
    }

}
@RunWith(value = SpringJUnit4ClassRunner.class)必须要写,相当于提供了spring的环境
@ContextConfiguration(locations = { "classpath:/config/**/applicationContext*.xml" }, loader = GenericXmlContextLoader.class)
加载config下的所有目录下的以applicationContext的xml文件,加载相应的配置文件
@Transactional  测试方法会进入事务管理

pom文件,引入junit的jar包,最好是4.10版本以上的
<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.10</version>
    <scope>test</scope>
</dependency>

 2017-08-03 20:19:26

idea下maven项目下spring junit 测试用例

原文:http://www.cnblogs.com/mkdlf/p/7275454.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!