码迷,mamicode.com
首页 > 编程语言 > 详细

spring-mvc junit测试

时间:2016-05-13 19:00:06      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:

import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

/**
 * Created by jecyhw on 16-5-12.
 */
@RunWith(SpringJUnit4ClassRunner.class)//使用Spring整合Junit的测试类测试
@ContextConfiguration(locations = {//spring-mvc配置文件
        "file:src/main/resources/applicationContext.xml"
})
@TestPropertySource(locations = {//所用到的properties文件
        "file:src/main/resources/mongodb.properties",
        "file:src/main/resources/weixin.properties"
})
abstract public class BaseTest extends AbstractJUnit4SpringContextTests {
    //其他所有test继承BaseTest即可
}
//简单的测试类
public class EventDaoTest extends BaseTest{

    @Resource
    EventDao eventDao;

    @Test
    public void list() {
        JsonUtil.writeAsString(eventDao.list());
    }
}

 

spring-mvc junit测试

标签:

原文地址:http://www.cnblogs.com/jecyhw/p/5490226.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!