第一种方式: //spring整合junit4 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.SpringJUnit4ClassRunner; /** * Created by staunch on 2016-07-12. * version:v1.0 * instruction:初始版本 */ @RunWith(SpringJUnit4ClassRunner.class) // 整合 @ContextConfiguration(locations="classpath:config/applicationContext.xml") // 加载配置 public class AdvisorServiceTest { @Autowired private //注入测试依赖 @Test public void testCheckStudentInfo() throws Exception { //测试代码 } } 第二种方式: //Spring+testNG import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.testng.AbstractTestNGSpringContextTests; import org.testng.annotations.Test; import java.util.ArrayList; import java.util.List; /** * Created by staunch on 2016-06-29. * version:v1.0 * instruction:初始版本 */ @ContextConfiguration(locations = {"/config/applicationContext.xml"}) public class AdvisorMapperTest extends AbstractTestNGSpringContextTests{ @Autowired //注入的测试依赖 @Test public void testBatchInsertDiscussion() throws Exception { //测试代码 } ); }
Spring 中的单元测试
猜你喜欢
转载自1551385390.iteye.com/blog/2313945
今日推荐
周排行