所需要的包:
junit需要是4.5以上
org.springframework.test-XXX.RELEASE.jar
package test; 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 com.works.dao.AosBusinessCoolingDao; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations={"/config/spring/applicationContext.xml"}) public class TestSpringTest extends AbstractJUnit4SpringContextTests { @Autowired private AosBusinessCoolingDao aosBusinessCoolingDao; @Test public void show(){ aosBusinessCoolingDao.findAosBusinessCoolingById(Integer.valueOf(2)); System.out.println("show"); } }
Junit与spring TestContext框架整合,布布扣,bubuko.com
原文:http://blog.csdn.net/zhanyan_x/article/details/25720829