All Questions
54
questions
0
votes
0
answers
10
views
Junit expecting a 400 response but getting a 200
I am trying to test my springboot controller /save endpoint. I want to test that if you send a json request with a null agency name you should get back a 400 status and the response "Agency Name ...
0
votes
0
answers
38
views
Spring Boot test: Why is my response body empty when testing a POST request?
I'm trying to test a POST endpoint in my Spring Boot application that creates a ChallengeReport. However, the response body is always empty, even though the status code is correct. I need help ...
0
votes
0
answers
96
views
MockMvc get perform returns status 200 but without response body
I have an issue with REST Controller testing:
@WebMvcTest(PersonController.class)
public class Testing {
@MockBean
PersonService personService;
@MockBean
...
0
votes
1
answer
517
views
Page Not Found -- No mapping for /GET
I am trying to write test for my controller for my SPRING-BOOT CRUD operation project using junit5 and mocking. While running the test it is showing below error. Not able to understand what is the ...
0
votes
0
answers
72
views
Get method by pathVariable in postMan passed but in mockMvc faile and return 404 error
I have a get type method in the controller in Spring Boot, which is passed in Postman and returns data, but in MockMvc it failed and gives a 404 error.
<groupId>org.springframework.boot</...
0
votes
2
answers
631
views
Using MockMvc inside of @BeforeAll static method
I am writing some integration tests in which I need to send in an api call to create a resource and then perform subsequent api calls based on that resource. I wanted to send the first call inside my @...
0
votes
2
answers
492
views
Getting NullPointerException in Unit test for MockMvc performed
I'm running a Unit test In my application's Controller and I'm getting a NullPointerException. Here are the details.
The Controller:
@RestController
@CrossOrigin
@RequestMapping("/api/users")...
0
votes
0
answers
173
views
How to have MockMvc use the same HttpServletRequest as the Controller when HttpServletRequest is part of the constructor?
I am using MockMvc to test a controller. The controller has an ObjectMapper and HttpServletRequest as arguments. I instantiate the controller in my test class with these arguments. When I use MockMvc ...
0
votes
0
answers
561
views
How can I get my Maven/Mockito mock MVC test to print out a more detailed stack trace?
I'm using JUnit 5 and the spring-boot-starter-test (v 1.5) for Maven. I would want to test a controller method using mock MVC ...
@ExtendWith(MockitoExtension.class)
public class MyControllerTest {
...
0
votes
1
answer
767
views
Spring boot @RestController test code error
I created a test code for @RestController on the spring boot and this error occurs.
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.cache....
0
votes
0
answers
426
views
Spring Boot Test model attribute does not exist
Im trying to test a controller, Author Controller, which returns a view with a model. The problem is on the testInitUpdateAuthor() test where its not able to find the model or attribute name ...
0
votes
1
answer
2k
views
Spring Boot MockMvc Authentication Object Is Null
@DeleteMapping("/uri/{id}")
public ResponseEntity<RestResponseBody> delete(@PathVariable Long id, Authentication auth) {
return ResponseEntity.ok(new RestResponseBody());
}
This ...
2
votes
1
answer
5k
views
Mockmvc returns empty response body even if response status is 200
I am trying to learn Junit and I ended up in a situation where my testcase returns 200 status code but returns null response Body. Its just a simple save operation using JPA repo and I have tried many ...
0
votes
1
answer
3k
views
Junit Test for Controller with parameters
Hi I'm trying to write Junit test for a controller but cant seem to find the proper approach can anyone please suggest how could write a junit test case for the following controller:
Contoller Class
...
0
votes
2
answers
772
views
Java MockMvc Test and Match Json String
i want to match output of get-request, and match with manual provided json string, basically copy one json string coming out of whole output and test. Tried lot of ways but its not happening, i can't ...