2013-07-04 2 views
5

Ich versuche, hier in meinem Endpunkt (Feder 3.1, junit 4.11) eine der Methoden zu testen, meine Codes sind: applicationContext.xml:@TestExecutionListeners nicht vorhanden ist für die Klasse

<?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> 

und Testklasse:

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)); 
} 
} 

Wenn ich Test ausgeführt habe ich bekam:
org.springframework.test.context.TestContextManage r retrieveTestExecutionListeners
INFO: @Test ExecutionListeners ist nicht vorhanden für Klasse [Klasse app.tests.TableTest]: Standardwerte verwenden. Ich habe danach gesucht, aber keine Informationen gefunden. Danke für die Hilfe!

Antwort

8

Sie vermissen die TestExecutionListeners. Fügen Sie diese Anmerkung zu Ihrer Klasse hinzu

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