spring-mvc junit测试

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());
    }
}

 

posted on 2016-05-13 17:45  jec  阅读(437)  评论(0编辑  收藏  举报

导航