Skip to main content
The 2024 Developer Survey results are live! See the results

All Questions

Tagged with
0 votes
0 answers
9 views

JUnit test failing Status expected:<201> but was:<404>

I've spent a lot of time trying to figure out this issue, but when I'm running my tests on my UserControllerTest class I'm getting Status expected:<201> but was:<404>. Here's my ...
dom's user avatar
  • 28
0 votes
0 answers
13 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 ...
Abby's user avatar
  • 9
0 votes
0 answers
46 views

When I perform spring-boot unit testing, the spring datasource is repeatedly initialized

I'm using Groovy + Spock to perform unit testing for a Spring-boot project. I have two test classes, Test Class A and Test Class B. These two test classes are independent and have no dependency ...
Mike Wu's user avatar
0 votes
0 answers
34 views

Spring Security || Unit Test with @WithAnonymousUser user keeps getting a 401 response

For an e-commerce project I've secured and unsecured end-points. When testing the endpoints manually in Postman everything works as expected. The unit test for the secured endpoints give the result I ...
Mrtijn's user avatar
  • 1
0 votes
1 answer
37 views

JUnit test using JsonPath start failing after adding Twilio dependency

The question is not about how to convert the response to json, but why did the tests start failing? The controller returns user information using a Java record object @PostMapping("/login") ...
DSG's user avatar
  • 1
1 vote
2 answers
132 views

How to enable DEBUG level for unit tests in Springboot 3.1.10?

I need to enable debug mode globally, so output from the application classes is logged in both application and unit tests. I enabled DEBUG mode in src\main\resources\application.properties and it ...
tim bits's user avatar
0 votes
0 answers
51 views

How to mock a static method call inside another static class using Mockito in Java?

I have a Java class OuterClass with a static method getInnerClass(). I want to write a unit test for a method that invokes getInnerClass().getType() and mock the behavior of getType(). Here's a ...
Aryan Gupta's user avatar
0 votes
0 answers
55 views

How write Junit test for custom Authentication Provider

I have a custom Ldap Authentication provider which is not called during my tests due to the mocks(I think). Is there any way to write junit testcases for Authentication provider implementation? Test ...
softechie's user avatar
  • 133
1 vote
1 answer
68 views

Clean way to kick-start a Spring Integration poller in JUnit integration test

I have a Spring Integration flow that makes use of a MessageSource to periodically populate messages from a database query (no, I didn't intend to use Spring Integration JPA/JDBC) @Bean public ...
usr-local-ΕΨΗΕΛΩΝ's user avatar
0 votes
0 answers
60 views

How I fix 404 error when test the spring boot using junit with m:m relationship

I am using Spring Boot 3 and have two entities: "Event" and "User". The relationship between these entities is many-to-many. A user can add many events, and an event can have many ...
Reham Almutairi's user avatar
0 votes
1 answer
90 views

Stubbing void method of spybean failing

I have a void method bar in a service Foo as shown: @Component @EnableAsync @AllArgsConstructor public class Foo { private final SomeOtherService someOtherService; private final ...
zeeshan's user avatar
  • 35
1 vote
0 answers
39 views

Test CompletableFeature.exceptionally(Ex) inside public method

writing test cases for following code but not able to cover exceptionally part of completable feature CompletableFuture<Optional<A>> aFuture = CompletableFuture.supplyAsync(()->Optional....
vishvas chauhan's user avatar
0 votes
0 answers
140 views

Spring Boot Test with CSRF and SpaCsrfTokenRequestHandler - MockMvc api with csrf does not work

I am trying to use Spring Boots suggested SpaCsrfTokenRequestHandler that will use the double submit cookie pattern for CSRF but the MockMvc api with csrf() does not seem to support this when it comes ...
Jcov's user avatar
  • 2,229
0 votes
1 answer
76 views

Parametrized test annotation not working with Spring Boot

I have the following snippet in my test class @ContextConfiguration(initializers = TestingV2.Initializer.class) public class TestingV2 extends BaseTest0IT { private static Stream getParams() { ...
curiousengineer's user avatar
0 votes
0 answers
36 views

How can I re-create the spring application context for parametrized tests with dynamic properties?

Environment Spring Boot 3.2.x JDK 21 JUnit 5.10.x Scenario Imagine that the following test case exists: @SpringBootTest(properties = "my.flag=1") @EnableConfigurationProperties(...
Misagh Moayyed's user avatar

15 30 50 per page
1
2 3 4 5
35