标签:
直接以代码方式演示如何在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()); } } }
标签:
原文地址:http://blog.csdn.net/gaohuanjie/article/details/43964193