Questions tagged [spring-test-mvc]

spring-test-mvc based on spring-test provides a unit testing framework for spring-mvc services.

spring-test-mvc based on provides a unit testing framework for services.

spring-test-mvc might be included in the Spring Framework version 3.2.x

Spring One DC 2012 slides

356 questions
2
votes
2 answers

Spring MVC RestController test failed to find valid mapping

I failed to test RestController method with path variable INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapped URL path [/my/{env}] onto handler 'myController' INFO…
2
votes
2 answers

java.lang.NoSuchMethodError: javax.servlet.http.HttpServletResponse.getStatus()

Getting error java.lang.NoSuchMethodError: javax.servlet.http.HttpServletResponse.getStatus() In pom.xml, I have mentioned 2 dependencies javax.servlet
Pramod Waghmare
  • 1,273
  • 13
  • 21
2
votes
4 answers

Error while running spring boot tests, SpringRunner.class Not found

When I try to invoke JUnit test cases from my Spring Boot Application, I am getting following error: I am using this annotation in my Test class. @RunWith(SpringRunner.class) After I add JUnit library from project dependencies, it gives me…
2
votes
1 answer

How to mock BindingResult in Spring Boot Test

I have the following controller: @RestController @RequestMapping(value = ROOT_MAPPING) public class GatewayController { @Autowired private RequestValidator requestValidator; @InitBinder protected void initBinder(WebDataBinder…
knemr57
  • 57
  • 2
  • 7
2
votes
1 answer

No qualifying bean of type [org.springframework.test.web.servlet.MockMvc] found for dependency:

I am trying to run test cases on my spring controllers. I get the following error. No qualifying bean of type [org.springframework.test.web.servlet.MockMvc] found for dependency: expected at least 1 bean which qualifies as autowire candidate for…
Siddharth
  • 9,349
  • 16
  • 86
  • 148
2
votes
1 answer

How test Post request with custom object in content type application/x-www-form-urlencoded?

I have controller: @PostMapping(value = "/value/", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE) public String updateSettings(final Dto dto) { System.out.println(">>> " + dto); return "template"; } Controller…
makson
  • 1,975
  • 3
  • 23
  • 31
2
votes
1 answer

What is asyncDispatch() alternative in REST-assured library

I want to use the REST-assured for testing my REST API instead of Spring's MockMvc. The idea is that I want to get the status code from the response of the async call using REST-assured library. Check below for details: I use these…
dk7
  • 678
  • 2
  • 10
  • 26
2
votes
1 answer

Spring MockMvc redirect not working

I am trying to mock a post request using the below code . I am testing a spring security login request. MockMvc mvc = MockMvcBuilders.webAppContextSetup(context).addFilter(springSecurityFilterChain) .apply(springSecurity()) …
lives
  • 1,243
  • 5
  • 25
  • 61
2
votes
3 answers

Custom RequestMappingHandlerMapping with MockMvc

I have a custom RequestMappingHandlerMapping class that interprets a special annotation as part of its mapping criteria. It is being instantiated as a bean thusly: @Configuration @EnableWebMvc public class ConfigServletConfig extends…
2
votes
1 answer

Is there any advantage in using MockRestServiceServer over simply mocking a RestTemplate?

In our code, we use Spring's RestTemplate to make an HTTP request and deserialize the response to a POJO. That's it. Any exceptions that might be thrown are propagated up and returned as an HTTP/500 response. We don't take any action based on the…
jmrah
  • 5,715
  • 3
  • 30
  • 37
2
votes
1 answer

Spring Boot Integration Test Inject Controller Dependencies

I am trying to write an integration test using Spring Boot that tests the transaction logic in one of my controllers. What the test should do, is the following: Inject one of my controllers using @Inject Replace an email dependency in the…
lanoxx
  • 12,249
  • 13
  • 87
  • 142
2
votes
2 answers

How do I test form submission with Spring MVC test?

Most of my experience with creating controllers with Spring are for REST controllers that consume JSON formatted requests. I've been searching for documentation on how to do testing for form submission, and so far this is how I understand it should…
Psycho Punch
  • 6,418
  • 9
  • 53
  • 86
2
votes
1 answer

Spring testing - test endpoint with mock controller

I have an existing app that I'm trying to write unit tests for... There is no real 'service' layer. It goes controller->repository->database and the endpoints are defined via annotations on the controller. I'm using Spring Boot 1.3.8 (not 1.4). What…
Mike
  • 763
  • 2
  • 12
  • 25
2
votes
1 answer

Spring integration test - AuthenticationPrincipal not injected

I am trying to use kotlin in my project, which is REST API endpoints serving angularjs frontend. And I use spring rest doc for our api document. While migrating, I find my security context is not injected in test case. Test class with mockito-kotlin…
klc
  • 305
  • 1
  • 4
  • 15
2
votes
0 answers

@SpringBootTest behaves unexpectedly while running tests through maven (surefire)

I have a Spring Boot 1.4.1 project and here is the organization of my test classes: package com.service in src/test/java RunWith(SpringRunner.class) @SpringBootTest(classes = { ApplicationConfiguration.class }, webEnvironment =…