引用springtest jar包和其他相关jar包 以及junit4
首先写一个基类 引用AbstractTransactionalJUnit4SpringContextTests
如下
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:applicationContext.xml")
public class BaseTestCase extends AbstractTransactionalJUnit4SpringContextTests{
}
写一个测试类 继承基类 然后加载自己需要的spring.xml文件
测试方法要+ @Test 方法名要 名字+Test
@Resource注入dao接口
@ContextConfiguration(locations = "classpath:config/spring/test.xml")
public class DaoTest extends BaseTestCase{
@Resource
private TestDao testDao;
@Test
public void allTest(){
testDao.dotest();
}
}