我使用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