2013-07-04 31 views
5

Tôi sẽ cố gắng để kiểm tra một trong những phương pháp trong thiết bị đầu cuối của tôi (mùa xuân 3.1, junit 4.11) Dưới đây là mã của tôi: applicationContext.xml: lớp@TestExecutionListeners là không có mặt cho lớp

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/mvc" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:beans="http://www.springframework.org/schema/beans" 
xmlns: p="http://www.springframework.org/schema/p" 
xmlns:context="http://www.springframework.org/schema/context" 
xmlns:cache="http://www.springframework.org/schema/cache" 
xmlns:mvc="http://www.springframework.org/schema/mvc" 
xsi:schemaLocation="http://www.springframework.org/schema/mvc  
http://www.springframework.org/schem...ng-mvc-3.0.xsd 
http://www.springframework.org/schema/beans http://www.springframework.org/schem...-beans-3.0.xsd 
http://www.springframework.org/schema/context http://www.springframework.org/schem...ontext-3.0.xsd 
http://www.springframework.org/schema/cache http://www.springframework.org/schem...ring-cache.xsd 
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"> 

<context:component-scan base-package="app.controller, app.samples" /> 
<context:annotation-config/> 
<annotation-driven /> 

</beans> 

và thử nghiệm:

package app.tests; 
import app.samples.TableEndpoint; 
import static org.junit.Assert.assertTrue; 
import static org.junit.Assert.fail; 
import org.junit.Test; 
import org.junit.runner.RunWith; 
import org.springframework.beans.factory.annotation.Autow ired; 
import org.springframework.test.context.ContextConfigurat ion; 
import org.springframework.test.context.junit4.SpringJUni t4ClassRunner; 

@ContextConfiguration(locations = {"classpath:/WEB-INF/applicationContext.xml"}) 
@RunWith(SpringJUnit4ClassRunner.class) 
public class TableTest { 

public TableTest() { 
} 
@Autowired 
TableEndpoint tableEndpoint; 
@Test 
public void testTableEndpoint(){ 
String result = tableEndpoint.getDane().get(0); 
String expResult = "Learn python in 7 days"; 
if(!result.equals(expResult)){ 
fail("not equals"); 
} 
assertTrue(result.equals(expResult)); 
} 
} 

Nếu tôi chạy thử nghiệm tôi đã có:
org.springframework.test.context.TestContextManage r retrieveTestExecutionListeners
INFO: @Test ExecutionListeners không có trong class [class app.tests.TableTest]: sử dụng các giá trị mặc định. Tôi đã tìm kiếm về nó nhưng không tìm thấy một số thông tin. Cảm ơn vì sự giúp đỡ!

Trả lời

8

Bạn bỏ lỡ TestExecutionListeners. Thêm chú thích này vào lớp học của bạn

@TestExecutionListeners({ DependencyInjectionTestExecutionListener.class }) 
@ContextConfiguration(locations = {"classpath:/WEB-INF/applicationContext.xml"}) 
@RunWith(SpringJUnit4ClassRunner.class) 
public class TableTest { 
... 
}