主要参考:
https://www.ibm.com/developerworks/cn/java/j-lo-springunitest/
http://www.cnblogs.com/rainisic/archive/2012/01/22/Spring_Test_Framework.html
maven jar:
https://mvnrepository.com/artifact/org.springframework/spring-test/4.3.9.RELEASE
测试代码:
package mydms; import java.util.List; 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; import org.springframework.transaction.annotation.Transactional; import com.xmal.dms.dao.mapper.AbandonMovingToNewBedMapper; import com.xmal.dms.pojo.OccupancyInfo;
//下面注释很关键 @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("/applicationContext.xml") @Transactional public class SpringTest { @Autowired AbandonMovingToNewBedMapper abandonMovingToNewBedMapper; @Test public void QueryOccupancyWhereStatusIsTiaoFangTest(){ List<OccupancyInfo> OccupancyInfoList = abandonMovingToNewBedMapper.QueryOccupancyWhereStatusIsTiaoFang("调房"); System.out.println("OccupancyInfoList"+OccupancyInfoList); } }