读书人

Spring3.04跟Junit4

发布时间: 2012-10-15 09:45:25 作者: rapoo

Spring3.04和Junit4

在Spring3.x以上必须采用Junit4.8以上,否则可能出现问题。 在Spring相关的测试中如果使用事务采用AbstractJUnit4SpringContextTests
如果不采用事务管理采用AbstractJUnit4SpringContextTests,注意在spring中测试时候必须注意junit4中事务
默认测试中为回滚的了。
package com.easyway.web.services.component.job;import org.junit.Test;import org.junit.runner.RunWith;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.test.context.ContextConfiguration;import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;import org.springframework.util.Assert;@RunWith(SpringJUnit4ClassRunner.class)@ContextConfiguration(locations = {"classpath:services/service-*.xml","classpath:services/ext/service-*.xml","classpath:services/ext/YichengYunwei/service-*.xml"})public class InspectionJobTest extends AbstractJUnit4SpringContextTests{@AutowiredInspectionJob myJob;@Testpublic void testDoJob() {}}

?

读书人网 >编程

热点推荐