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
1 answer

how to test ModelAttribute parameter by MockMvc

I wrote this controller method: @RequestMapping("/submitFormAdd") public ModelAndView submitFormAdd( Model model, @ModelAttribute("myCandidate") @Valid Candidate myCandidate, BindingResult…
user2740224
2
votes
1 answer

Spring MVC + Tiles: integration testing

I try to write integration tests for my spring MVC app. Problem: It seems that TilesView can't resolve views in my spring mvc tests. In my test MockMvcResultMatchers.forwardedUrl() returns "/WEB-INF/jsp/layout.jsp", instead of…
VB_
  • 45,112
  • 42
  • 145
  • 293
2
votes
2 answers

jar for spring-test-mvc

I am trying to get a jar for Spring-test mvc. org.springframework spring-test-mvc 1.0.0.M1 test This dependency can´t be resolved.…
pethel
  • 5,397
  • 12
  • 55
  • 86
2
votes
1 answer

Spring test-mvc PUT not supported

This is my Controller method: @RequestMapping(method = RequestMethod.PUT,produces="application/json", headers = "content-type=application/json") public @ResponseBody User updateUser(@RequestBody User user) throws PropertyErrorException,…
lg.lindstrom
  • 776
  • 1
  • 13
  • 31
1
vote
0 answers

Test for controller returning "ResponseEntity" not seeing testdata

We have a controller returning a ResponseEntity. When writing mockMvc tests for this controller we use .andDo(MvcResult::getAsyncResult). For the controller to see the data we create in the database in the setup for the test…
Kaj Hejer
  • 955
  • 4
  • 18
1
vote
0 answers

Why are not these two objects equal in spring mvc test?

I am doing an mvc test in my program that the getRecipes() method is supposed to return a list of recipes. Also, the Recipe class has not overridden the equals method and the hashCode. As it is known in the RecipeService class, a new HashSet is…
fast
  • 51
  • 4
1
vote
1 answer

Spring MockMVC defaults wrong ContentType in Response

I've just updated my application to use spring-test 5.3.12 and Junit 5.7.2 but now my test are failing. With the previous version (5.2.X) the response type always was 'application/json' but now I'm getting this error: java.lang.AssertionError:…
dragonalvaro
  • 703
  • 1
  • 10
  • 28
1
vote
1 answer

Spring Mockmvc ignores unknown fields

The API method has already been validated with @Valid annotation. When I test this method using postman, and post an unknown field, it works, and rejects the request. However, when I test this using mockMvc, mockMvc ignores unknown fields. Any idea…
Tilmiz
  • 11
  • 1
1
vote
0 answers

Why can't I mock service dependency of controller when trying to test it using mockMvc?

I'm new to testing controller and web layer. I have Service which has methods to work with orders, and I have controller that has that service as dependency OrderService: @Service public class OrderServiceImpl implements OrderService{ …
DozezQuest
  • 179
  • 7
1
vote
1 answer

MockMvc peform is return nullPointerException in integration tests

I'm trying to run integration tests for my Spring project, it's a simple get method that returns a String output from the DB for the id given. But I keep getting a NullPointerException on the Mockmvc in the MockMvc.perform within my tests. Here is…
ejh97
  • 25
  • 1
  • 4
1
vote
1 answer

post or put form data in mock mvc

I want to write test for a controller that only accepts form data: @PostMapping("/signup/") public ResponseEntity signUpUser(@ModelAttribute UserModel user, HttpServletResponse response) throws Exception { return…
1
vote
1 answer

How to make spring boot test app independent of external property source?

I am writing a controller test for a spring boot application. To use the spring application context I am using SpringRunner class. The problem is the main application class has a property source defined to a specific file path. When I am running the…
1
vote
0 answers

JUnit 4 test failures after Java 11 (Corretto 11) and Spring 5 5.2.13.RELEASE upgrades, "Failed to load ApplicationContext"

As I mentioned in the title, we are migrating from Java8 with JUnit4&5 mixed and Spring4.3.11.RELEASE to Java11 and Spring5.2.13.RELEASE. I have the following maven version 3.8.1 configured under project/build/plugins sections,
BJYC
  • 354
  • 2
  • 10
1
vote
0 answers

Spring Boot Tests with Vivid Solutions

I have a controller to handle all my geometry's operations, it works just fine and it's already in use but, now that I try to make the tests it just doesn't work. I'm new at this test thing, but I think the problem is with JUnit that doesn't…
1
vote
1 answer

Why do MockMvc tests suggest injecting WebApplicationContext @BeforeEach test?

So the reference documentation suggests @BeforeEach void setup( WebApplicationContext wac) { this.mockMvc = MockMvcBuilders.webAppContextSetup( wac ) .apply( SecurityMockMvcConfigurers.springSecurity() ) …
xenoterracide
  • 16,274
  • 24
  • 118
  • 243