Directly on the code package dependency please add your own Maven added dependency is very convenient
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//some common "init" code 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 {@Resourceprivate jobservice jobservice; @Testpublic void Sendqtest () {list<job> List = Jobservice.findalljobs (); System.out.println (Jsonobject.tojson (list));}}
JUnit Spring Annotation Unit test