hibernate的Junit测试用例
我已经开发了一个web projectstruts2+hibernate,我需要对其进行代码覆盖。我不知道如何为这个hibernate部分编写junit测试用例。有人能给我一些建议吗?我希望我的测试用例检查我的数据库,如果我给出的输入不在数据库中,它应该会出错。 我使用EclipseIndigo,Mysql数据库,提前感谢hibernate的Junit测试用例,hibernate,struts2,junit4,testcase,Hibernate,Struts2,Junit4,Testcase,我已经开发了一个web projectstruts2+hibernate,我需要对其进行代码覆盖。我不知道如何为这个hibernate部分编写junit测试用例。有人能给我一些建议吗?我希望我的测试用例检查我的数据库,如果我给出的输入不在数据库中,它应该会出错。 我使用EclipseIndigo,Mysql数据库,提前感谢 package proj.dao.impl; import java.util.List; import org.hibernate.Session;
package proj.dao.impl;
import java.util.List;
import org.hibernate.Session;
import org.hibernate.Transaction;
import com.googlecode.s2hibernate.struts2.plugin.annotations.SessionTarget;
import com.googlecode.s2hibernate.struts2.plugin.annotations.TransactionTarget;
import proj.dao.EmployeeDAO;
import proj.model.Employee;
public class EmployeeDAOImp implements EmployeeDAO{
@SessionTarget
Session session;
@TransactionTarget
Transaction transaction;
//return all the Employees in list
public List<Employee> listEmployee(){
return session.createQuery("from Employee").list();
}
}
仅此单独的测试用例
指向DAOImpl类中实际listemployee方法的空指针异常Idea:编写一些测试类并从那里调用DAO方法。@Aleksandr M我尝试过不为什么不起作用显示您尝试过的内容。到底什么不起作用?编辑你的问题,不要在注释中添加代码。@Aleksandr M编辑检查
package proj.Test;
import static org.junit.Assert.*;
import org.junit.Test;
import proj.dao.EmployeeDAO;
import proj.dao.impl.EmployeeDAOImp;
public class EmployeeDAOImplTest {
@Test
public void testListEmployee() {
EmployeeDAO dbo = new EmployeeDAOImp();
assertTrue("There were no errors in Register", dbo.listEmployee().size()!=0);
}
}