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

如何在Spring MVC工程中进行单元测试

时间:2015-02-27 10:08:44      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:

        直接以代码方式演示如何在Spring MVC工程中进行单元测试:

package net.chinaedu.projects.dubhe;

import java.util.List;

import net.chinaedu.projects.dubhe.publisher.IPublisherService;
import net.chinaedu.projects.venus.domain.Publisher;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@ActiveProfiles({"test"})
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:conf/spring/app-context.xml", "classpath:conf/spring/servlet-context.xml"})//指定工程中Spring配置xml文件
public class JUnit4Test extends AbstractJUnit4SpringContextTests  {//AbstractTransactionalJUnit4SpringContextTests

	@Autowired
    private IPublisherService publisherService;
    
    @Test
    public void testFindAllPublisher(){
    	List<Publisher> publisherList  = publisherService.findAll();
    	for (Publisher publisher:publisherList) {
			System.out.println(publisher.getId() + " , " + publisher.getName());
		}
    }
}

如何在Spring MVC工程中进行单元测试

标签:

原文地址:http://blog.csdn.net/gaohuanjie/article/details/43964193

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