一所需jar包.
1.首先加入Spring所需jar包
2.spring-test.jar
3.JUnit-4.5jar
二.代码:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations="classpath:applicationContext-bean.xml")
//如果要使用事务管理则继承AbstractTransationalJUnit4SpringContextTests(并在spring中配置transactionManager)
public class DaoTest extends AbstractJUnit4SpringContextTests
{
@Resource
private BaseDaoImpl baseDaoImpl;
@Test
public void getAllUser()
{
List<User> userList=(List<User>)baseDaoImpl.findAll(User.class);
System.out.println(userList.size());
}
}