我使用Spring与EXT JS和休眠来填充EXT JS表单使用tomcat的网页上...我有表使用访问数据库并返回我的HQL语句的方法填充JUnit测试:空指针异常
现在我试图执行一个简单的JUnit测试来算的返回的记录数,但是当我打电话的JUint测试填充Ext JS的形式方法,它返回excception ......我不知道为什么
JUnit测试类
package com.fexco.helloworld.web;
import static org.junit.Assert.assertEquals;
import java.util.List;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import com.fexco.helloworld.web.dao.CustomerDaoImpl;
import com.fexco.helloworld.web.model.Customer;
/**
* Unit test for simple App.
* /
public class CustomerServiceTest {
@Autowired
private CustomerDaoImpl customerDaoImpl;
@Test
public void findAllCustomersTest() {
List<Customer> list = customerDaoImpl.findAllCustomers();
int numberInDatabase = list.size();
assertEquals(5, numberInDatabase);
}
}
我的方法访问数据库
public List<Customer> findAllCustomers(){
List<Customer> list = getHibernateTemplate().find("from Customer");
return list;
}
和我的方法调用访问数据库
public List<Customer> returnAllCustomers(){
List<Customer> list = customerDaoImpl.findAllCustomers();
return list;
}
,你可以在这里看到,表格填充用同样的方法在JUnit从数据库项目的方法(findAllCustomers())
没有任何人有什么想法?
你需要添加一个依赖或东西的@RunWith(SpringJUnit4ClassRunner.class)来,因为它没有被日食认可 – newSpringer 2012-04-17 15:54:44
是的,你需要有弹簧Test.jar的。请参阅编辑 – vacuum 2012-04-17 16:04:29
哈,我发现它就在您放置编辑之前......干杯:) – newSpringer 2012-04-17 16:08:00