Questions tagged [spring-mvc-test]
241 questions
0
votes
1 answer
Spring 5 MVC Test with MockMvc, test-context.xml, and annotation-based WebAppConfig (ie, in Java)
Versions (SpringBoot is not involved):
Spring: 5.2.16
web-app / servlet API: 4.0
JUnit: 5.8
Spring MVC Testing is not working for controller endpoint that returns ResponseEntity, where ReturnStatus is a POJO with appropriate…

Kode Charlie
- 1,297
- 16
- 32
0
votes
1 answer
MockHttpServletResponse has empty in test, despite Controller working correctly
I'm testing a @RestController POST endpoint using MockMvc.
In this test, the MockHttpServletResponse content is always empty & the content type is not set.
I checked the controller method; it's getting called and returns the right response.
The…

Nice Books
- 1,675
- 2
- 17
- 21
0
votes
1 answer
My controller code is not reachable from the MockMvc get request and i am always getting 404
I am trying to mock my controller and write testcases for it. But when I tried to debug the Test class the control is not getting into my Controller class. I am not sure what I am doing wrong here.
Please help me to resolve this as I am stuck on…

harish
- 13
- 4
0
votes
1 answer
Is there a way we can load properties from src/test/resources/application.properties in spring boot test?
@ExtendWith(SpringExtension.class)
@WebMvcTest(MyClass.class)
@TestPropertySource(locations="classpath:application-test.yml")
//Something like this?

Murugan
- 51
- 6
0
votes
1 answer
Configuration for Mvc testing
guys. I have spring MVC project and I want to test CoursesController, but can not find out how to do it.
Do I need to make separated configuration class for tests?
Before springMvc I used separated configuration class for test with embedded…

BM9
- 21
- 6
0
votes
1 answer
How to make Constructor for entityclass in springboot that extends mappedsuperclass
step1: I have mappedsuperclass that has constructor.
@MappedSuperclass
public abstract class CommonConfig{
@JsonFormat
@Column(name ="LastModifiedTime")
@Temporal(TemporalType.TIMESTAMP)
protected Date lastModifiedTime;
…

kavin G
- 15
- 1
0
votes
1 answer
Spring MVC Unit Testing - Mocked Service method is not called
I was working on a spring boot project where I have controller which calls a service method and process the output.
I'am using spring MockMvc for testing the web layer. In my test class I have mocked the service method with Mockito.when(). But when…

Venkat
- 139
- 1
- 8
0
votes
1 answer
Why is Spring Security CSRF check failing when using MockMVC MockMvc
Sorry for the information overload, I would think that a lot more information is here than needed.
So I have this test code
package com.myapp.ui.controller.user;
import static…

xenoterracide
- 16,274
- 24
- 118
- 243
0
votes
2 answers
Spring MVC controller test fails with empty body
I am writing a small REST API with spring boot and trying to write the MVC test.
Unfortunately the MVC tests fails as I get the empty response from the controller.
Controller class:
@RestController
@RequestMapping("/test")
public class…

G.S
- 10,413
- 7
- 36
- 52
0
votes
2 answers
Format specifiers should be used instead of string concatenation in java
I am writing code the below code
Logger.error("Error in x file :",+ e.getMessage());
But for the above line of code I am getting the error to use format specifiers instead of string concatenation. How should I fix it?

ritu4
- 11
- 1
- 2
0
votes
0 answers
JUtit test Exception of java.lang.NoSuchMethodError: org.springframework.util.Assert.notNull
When I debug the File as Junit then it will throw exception couldn't figure it out ...
package com.fort313.webexmd.test;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import…

Asad Malik
- 1
- 1
- 2
0
votes
1 answer
Demystifying Spring framework
With multiple ways to configure using either XML, Annotations or Java Config and the need to remember 100's of annotations and super-lengthy class-names, the Spring framework appears an extremely complex demon that cannot be understood. Moving from…

Ali
- 83
- 1
- 7
0
votes
1 answer
Spring Boot Test - Mockito - Service call return null
I'm testing a post method in my controller that only return a String and using Mockito to mock the service call. My problem is that when the service method is called on controller it return…

Aldo Inácio da Silva
- 824
- 2
- 14
- 38
0
votes
1 answer
UriComponentsBuilder/MvcComponentsBuilder usage in a Spring Boot Test
I've put a very simple sample project on GitHub to reproduce the problem.
The main issue is that I have a PersonController that has a PutMapping to create a new person. In order to populate the Location header with the URL to fetch that person, I…

Mekswoll
- 1,355
- 3
- 15
- 35
0
votes
0 answers
How to unit test java code, which is using Reflections to populate subTypesOf a class?
This is my code:
protected void loadConverters() {
// load all available converters
Reflections reflections = new Reflections("com.mypackage.MyClass");
Set> processors =…

rishabh
- 1,155
- 1
- 10
- 17