直接上代码包依赖请自行加入maven添加依赖很方便
1、TestBase.java
package com.test; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.junit.Before; import org.junit.runner.RunWith; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @RunWith(SpringJUnit4ClassRunner.class) @ActiveProfiles("junit") @ContextConfiguration(locations = { "classpath*:spring/applicationContext.xml", "classpath*:com/ibm/uam/**/META-INF/beans.xml", "classpath*:com/ibm/common/**/META-INF/beans.xml", "classpath*:spring/spring-mvc.xml" }) public class TestBase { protected Log logger = LogFactory.getLog(TestBase.class); @Before // 一些公用的“初始化”代码 public void before() { } }2、JobTest.java
package com.test; import java.util.List; import javax.annotation.Resource; import org.junit.Test; import com.alibaba.fastjson.JSONObject; import com.userorg.entity.Job; import com.userorg.service.JobService; public class JobTest extends TestBase { @Resource private JobService jobService; @Test public void sendQTest(){ List<Job> list = jobService.findAllJobs(); System.out.println(JSONObject.toJSON(list)); } }
原文:http://blog.csdn.net/lantianzhange/article/details/41048355