I will try to test one of methods in my endpoint (spring 3.1, junit 4.11) Here are my codes: applicationContext.xml:
<?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>
and test class:
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));
}
}
If I run test I have got :
org.springframework.test.context.TestContextManage r retrieveTestExecutionListeners<br>
INFO: @TestExecutionListeners is not present for class [class app.tests.TableTest]: using defaults.
I searched about it but didn't find some informations. Thanks for help!
TestExecutionListener defines a listener API for reacting to test execution events published by the TestContextManager with which the listener is registered. Note that not all testing frameworks support all lifecycle callbacks defined in this API. For example, beforeTestExecution(org. springframework. test.
The @SpringBootTest annotation is useful when we need to bootstrap the entire container. The annotation works by creating the ApplicationContext that will be utilized in our tests. We can use the webEnvironment attribute of @SpringBootTest to configure our runtime environment; we're using WebEnvironment.
You miss the TestExecutionListeners. Add this annotation to your class
@TestExecutionListeners( { DependencyInjectionTestExecutionListener.class })
@ContextConfiguration(locations = {"classpath:/WEB-INF/applicationContext.xml"})
@RunWith(SpringJUnit4ClassRunner.class)
public class TableTest {
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With