Я обновил свою зависимость Spring до Spring 3.1.1.RELEASE и пытаюсь использовать spring-test-mvcдля модуля протестировать простой контроллер. Я следовал методике, использованной в Spring REST Controller Test с spring-test-mvc framework, так как она, кажется, сработала для этого человека, но пока безуспешно. Я думаю, что в моем тестовом файле контекста отсутствует какая-то ключевая конфигурация.
Я не получаю ошибок. Причина, по которой я знаю, что это не работает, заключается в том, что Hello World
никогда не печатается (см. Контроллер). Что я здесь отсутствует?
Контроллер:
@Controller
@RequestMapping("/debug")
public class DebugOutputController {
@RequestMapping(method = RequestMethod.POST)
public void saveDebugOutput(@RequestBody DebugOutput debugOutput, HttpServletResponse response) {
System.out.println("Hello World");
}
}
Тестовый класс:
@RunWith(SpringJUnit4ClassRunner.class) //this lets tests access Spring beans defined in the context config file
@ContextConfiguration(locations={"file:src/test/resources/itest/restAPITestContext.xml"}) //tells the test where to get configuration and beans to be used by the test.
@TestExecutionListeners({DependencyInjectionTestExecutionListener.class, TransactionalTestExecutionListener.class}) //overrides the default stack of listeners
public class ITRestAPI{
@Autowired
private DebugOutputController debugOutputController;
private MockMvc mockMvc;
@Before
public void setUp() throws Exception {
mockMvc = MockMvcBuilders.standaloneSetup(debugOutputController).build();
}
@After
public void tearDown() throws Exception {
}
@Test
public void shouldPerformPost() throws Exception {
this.mockMvc.perform(post("/debug"));
}
}
restAPITestContext.xml: