All Questions
147
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 ...
1
vote
2
answers
122
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 ...
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 ...
0
votes
1
answer
86
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 ...
0
votes
1
answer
74
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() {
...
0
votes
0
answers
35
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(...
0
votes
0
answers
50
views
Junit mock throwing completion exception from private methods using completable future chain
I've this public method in service class which has chain of CompletableFuture
public InfoResponse getInfoFromService(Request request) {
...
List<CompletableFuture<Void>> ...
0
votes
0
answers
140
views
Problem when executing integration test and veryfing a list of beans with Mockito
Hello i'm facing a problem when verifying if an interface implementation was called on a integration test.
I have a service handler that injects a list of all interface implementations and executes ...
0
votes
1
answer
391
views
Assertions on ApplicationEvents in Spring Boot Test using @RecordApplicationEvents fail unexpectedly
I am writing some improvements in my code that use classes inheriting an ApplicationEvent (e.g. UserSubscribedEvent). In my test I want to validate that the @Service did execute the expected logic (c....
0
votes
1
answer
180
views
Spring Boot Test - Async method in test suite does not work
I'm writing a test class and I want to verify that a method annotated with Async and returning a CompletableFuture executes a branch of code
WHAT IS USE
Spring Boot 3.x
Mockito
Spring Test
Spring ...
1
vote
1
answer
331
views
Disable Eureka client initialization during JUnit test run
I have this Junit 5 test which is used to test Rest API calls:
@SpringBootTest
@AutoConfigureMockMvc
@ExtendWith(MockitoExtension.class)
public class ControllerTest {
@MockBean
private ...
0
votes
1
answer
25
views
How to access a filed(or its getter and setter) in a RestController in Junit WebMvcTest?
Currently I'm writing unit tests for a spring boot application using Junit and Mockito. The problem I've encountered recently is that we have a RestController class which has some fields.
some of the ...
0
votes
1
answer
652
views
JUnit testing for Spring @Retryable maxAttempts not working
I have used Spring's retry in my project to achieve retry functionality for specific exceptions.
SomeService.java
@Service
@Slf4j
public class SomeService implements AuthenticationService {
...
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
1
answer
168
views
Can't autowire method in spring boot test
I'm trying to test a Login with JWT but everytime I try to test this method it gives me a:
java.lang.NullPointerException: Cannot invoke "it.security.jwt.JwtTokenUtil.generateToken(org....