All Questions
Tagged with spring-boot junit
2,369
questions
0
votes
2
answers
545
views
Request Processing failed with null pointer exception because Cannot invoke Service class as it is null
Request Processing failed with null pointer exception because Cannot invoke Service class as it is null.
I am trying to write the test cases for my controller class.
This is my User Controller class
@...
0
votes
0
answers
107
views
How to write unit tests for Constraints where it is applied penalizeConfigurable() method in Timefold?
Starting from the github project provided by Timefold (https://github.com/TimefoldAI/timefold-quickstarts/tree/stable/technology/java-spring-boot) and extend it by using ConstraintConfiguration and ...
0
votes
0
answers
59
views
How do I run JUnit tests using Maven via console?
I'm doing the https://spring.academy/courses/spring-framework-essentials/lessons/spring-essentials-aop-lab-demo and struggled with the console output until I ran it inside the Spring Tool Suite 4 and ...
0
votes
1
answer
102
views
unit-test search method (querydsl) with mockito
In my springboot app I'm trying to write a unit test for my search method using mockito:
Service:
QRental qRental = QRental.rental;
var jpaQuery = new JPAQuery<Rental>(entityManager)
...
0
votes
0
answers
32
views
How to fix: Java.lang.NoSuchMethodError:org.mockito.MockitoAnnotations.openMocks(Ljava/lang/Object;)Ljava/lang/AutoCloseable
I have updated Maven from 4.0.0-alpha-3 to 4.0.0-alpha-12. Build is failing with the following error:
Java.lang.NoSuchMethodError: org.mockito.MockitoAnnotations.openMocks(Ljava/lang/Object;)Ljava/...
1
vote
0
answers
56
views
jakarta.servlet dependencies mismatch while upgrading spring version [duplicate]
dependencies mismatch while upgrading spring version.
I am upgrading my service with spring boot 3.1.4.
This is my build.gradle.
plugins {
id 'org.springframework.boot' version '3.1.4'
id 'io....
0
votes
2
answers
36
views
MockMultipartFile is not included in MockHttpServletRequest
I wanna test what happens when the oversized image file is sent to spring boot server using MockMultipartFile.
@SpringBootTest
@AutoConfigureMockMvc
class PostControllerTest {
@Autowired
...
0
votes
0
answers
332
views
The Redis container does not run as a testcontainer
I do integration tests using Spring Boot, TestContainers, redis and Junit 5.
The code was written for the test as follows.
@Testcontainers
public class RedisTestConfig {
private static final ...
-2
votes
1
answer
38
views
Unit testing code having database dependency
I am using Junit4 in Spring boot application. I am able to write tests that don't have dependency on database but facing trouble in testing code having DB dependency. Like below test is for a method ...
0
votes
1
answer
117
views
Spring Boot and MockServer with GET 'body' lead to different result with test env and actual app run
Well I have JUnit 5 test which do API checking, and client which has common code like this
ResponseEntity<T> responseEntity = restTemplate.exchange(url, method, httpEntity, clazz);
but with GET ...
0
votes
0
answers
40
views
Actual response is returning null in unit test using JUnit 4.12
So, i'm trying to create a unit test since its my first time doing this and here is the code:
package com.convergeict.shoppingcartservice.controller;
import com.convergeict.shoppingcartservice.model....
0
votes
1
answer
75
views
Null pointer Exception in spring boot testing
I have recently started to learn spring boot junit testing using mockito, but i get stuck very often. Here's my problem:
I have created a simple addEmployeeTest, which results in null pointer ...
0
votes
0
answers
54
views
Why this mocked StringBuilder always return the string "stringBuilder" ? Posibly confiusion with Junit mocks
Hello and sorry for my english. Im new in Junit and im trying to learning mocks and how it works, well, I have this test class with the next mocks:
@DataJpaTest
@AutoConfigureTestDatabase(...
1
vote
1
answer
733
views
jacoco test report configurations from build.gradle file causing build failure
After importing an existing project, gradle build for spring boot is failing in my local. This same project I have been able to build successfully before.
The error in console is:
Build file 'C:\Users\...
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
...