All Questions
Tagged with spring-boot junit
2,368
questions
1
vote
0
answers
18
views
SpringBootTest with Togglz
I just recently added togglz to the spring-boot 3.1.9 application, which contains also much stuff like spring-security, spring-data, etc.
Maven dependency:
<dependency>
<groupId>org....
0
votes
0
answers
19
views
Dependency not getting mocked in unit test
I am trying to run a unit test for my springboot controller as:
@WebMvcTest(controllers = MyController.class)
@ExtendWith(SpringExtension.class)
public class MyControllerTest {
@Autowired
...
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
37
views
Spring Boot microservices with JWT (Cannot run Integration test (401 Unauthorized Error))
I try to implement an example of Spring Boot microservices with JWT. I have some problem. I cannot run all integration tests of product service even if I defined bearer token in terms of admin and ...
-1
votes
2
answers
59
views
How to write a unit test with a controller method that has protected code in it [duplicate]
I am trying to write a unit test for the following controller:
@RestController
@RequestMapping(value = ENDPOINT_URL)
public class MainController extends RestControllerBase {
MainService ...
0
votes
1
answer
48
views
How to use class member variables inside Junit-Mockito tests
class MyClass {
MyErrorServiceList myErrorServiceList; // myErrorServiceList is initialized by some complex method calls
public boolean processErrorServiceList() {
if (...
0
votes
0
answers
33
views
I created a test case method named 'testRegisterCustomerSuccess,' but it encountered issues related to JPA queries
I have a method named registerCustomer in a service implementation class. I created a test case named testRegisterCustomerSuccess for this method in a class named UserServiceImplTest, where I mock ...
0
votes
0
answers
32
views
Mock WebClient webflux bean with Qualifier
I have the following scenario:
A config class with two WebClient beans with different names
public class WebClientConfig {
@Bean("bean_1)
public WebClient getWebClient1(WebClient.Builder ...
0
votes
1
answer
71
views
Unable to pass multipart file through mockMvc
I am writing junit test for my request method. Im using mockMvc to trigger the rest request.
When I run my test I get the error
java.lang.NullPointerException: Cannot invoke "org.springframework....
0
votes
0
answers
31
views
Junit for GCS files reading in spring boot
I have an application in spring boot where I am fetching multiple files from GCS and then iterate to read file content. I am able to mock gcs storage but not able to mock the file content. I want to ...
1
vote
1
answer
38
views
Sprinboot api application performance test
I want to test the performance of my backend REST API application written with Spring Boot under high requests.
How can I perform this process?
Which tools should I use and what should I do step by ...
0
votes
2
answers
56
views
Junit local object mock with arguments
I want to use mockito for mocking the constructor call when a specific argument is passed.
Lets say this is my class -
public class MyTestClass {
private final String argument;
public ...
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 ...
-1
votes
1
answer
39
views
In my Spring setup with DbSetUp + H2 database, queries with LIKE are not working
As the title suggests, what I want to do is test a class with database access in a Spring Boot application.
In the target class, I am using Specification as follows:
TestSpecification specification = ...
1
vote
1
answer
22
views
junit testing integrationFlow with serviceActivator
in my spring-boot project i have the following class :
@Configuration
@EnableIntegration
public class ConsumeFiles {
@Bean
public IntegrationFlow inboundFileFromDirectory(@Value("${...
0
votes
0
answers
38
views
How can I remove all running docker containers after all tests in a JUnit test suite have finished running?
I have a JUnit test suite that comprises of 3 smaller test suites. When these tests are run, 2 docker containers are spun up (an oracle slim db and an elasticsearch). I want to be able to remove these ...
0
votes
1
answer
49
views
How can I make a multiple level of mock object
Here is my example of object
@Service
public class UserSshKeyService {
private final RecordEventService eventService;
private final UserSshKeyRepository repository;
public ...
-1
votes
1
answer
164
views
How to mock a repository with Spring Data JPA + Specification
There is a basic CRUD API, and I want to test the UserServiseImpl.java class in its Service layer. In UserServiseImpl, entities are retrieved with
userRepository.findAll(query)
as shown below, and I ...
0
votes
1
answer
81
views
Mockito Test Fails with 'Wanted but not Invoked; Actually, there were zero interactions' Error
I'm facing issues with a unit test in a Spring Boot application where a specific repository method isn't being called as expected during the test of a service method. Despite setting up the test with ...
3
votes
1
answer
34
views
Test Coverage for DB call java code after couchbase 7.2 upgrade
We have recently upgraded Couchbase DB from 6.x to 7.2 . Which introduced collection and scope along with bucket. That means this
GetResult serviceInventoryJsonDocument = this.bucket....
1
vote
0
answers
89
views
How to mock constructors using mockito? [duplicate]
I am testing a method some class which has a new constructor call of BuildingBlockDbHandler.class. I was earlier using powermock to mock constructors like this way -
BuildingBlockDbHandler ...
0
votes
1
answer
48
views
How to write JUnit test for Gateway Application in Spring Boot Microservices
I have a problem to implement some JUnit test for Gateway Application in Spring Boot Microservices
Here is the Gateway Service Application shown below
@EnableDiscoveryClient
@SpringBootApplication
...
0
votes
0
answers
31
views
Testing method annotated with @Cacheable
I have to test a method thats annotated with @Cacheable like this im not,that skilled so this may be wrong.
@Trace
@Cacheable(value = "pp-search")
public Response search(final ...
2
votes
1
answer
73
views
Create uber file from Maven Surefire configuration
The current stack is Maven with modules per domain.
The main module imports the others.
And have a basic spring application on src and a testNG/cucumber/springboot runner on test.
I run that test ...
0
votes
2
answers
289
views
NoSuchMethodError: 'java.util.Set org.junit.platform.engine.TestDescriptor.getAncestors() when running Spock Spring Boot unit tests
Context
I have a unit test written using the Spock Testing framework to test my Spring Boot application.
I've declared the following test dependencies:
spock-spring: 2.3-groovy-4.0
spring-boot-...
0
votes
0
answers
52
views
SpringBoot configuration
I'm trying to run the following code using JUnit test (Run As -> JUnit Test).
I'm using Maven for dependency management, so I would have and understand that it's a configuration issue.
I've seen ...
0
votes
0
answers
51
views
Tests passing in IntelliJ, failing using mvn
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.junit.jupiter.MockitoExtension;
import static org.junit....
1
vote
0
answers
42
views
Inject JobLauncherTestUtils without using the @Autowired in unit test and spring batch
I'm new with Spring Batch and I'm trying to create an unit test for my job without using spring Boot and spring Batch annotations, only the mockito, however when i mock the JobLauncherTestUtils my ...
0
votes
1
answer
67
views
How can I delete all database entities after the tests are completed?
I was looking if there is a way with some kind of annotation rather than with code to clean the database after a test generated registries in it. I found about @Dirtiescontext but it doesn't seem to ...
0
votes
1
answer
39
views
Getting java.lang.NoClassDefFoundError Exception while using MockMvcBuilders.standaloneSetup() method in Junit 5
Below is my Test class that I have created for Controller class.
My Testclass is in package src/test/java and my java classes are in folder src/main/java.
public class MyControllerTest {
@...
0
votes
1
answer
34
views
JUnit run End-to-End Test with multiple Services
I am trying to run End-to-End tests with JUnit and RestTemplates.
I have a Spring / Maven Multi Module Project in the following structure:
parent
|-- service-1
|-- service-2
|-- service-3
|-- ...
0
votes
0
answers
168
views
IllegalState Failed to load ApplicationContext in GitHub Actions pipeline
I am getting IllegalState Failed to load ApplicationContext for for [WebMergedContextConfiguration@74764622 testClass = errors when GitHub runs my pipeline.
However the tests pass when I am running ...
0
votes
1
answer
44
views
How to test @Valid with JUnit5, @SpringBootTest?
This is my Controller class.
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind....
0
votes
1
answer
51
views
GraphQLTestTemplate returning "Body is empty with status 401" for SpringBoot and GraphQL integration testing
I have been working on integration testing using SpringBoot + GraphQL following this tutorial: https://www.youtube.com/watch?v=bdfEjn6xZx0 which I found pretty straightforward.
However, when I execute ...
2
votes
0
answers
125
views
Configure JUnit to run on 5 threads, each using a different datasource
TL;DR How to configure my JUnit test suite to run on 5 threads, each using a different datasource?
I'm trying to speed up my SpringBoot/JUnit 5 integration tests, which currently take over 40 minutes. ...
0
votes
0
answers
43
views
The application.properties values are not read in java tests
I have the following service, where I use the properties of my application.properties file:
@Service
public class TesoSunSystemsServiceImpl implements TesoSunSystemsService {
@Value(&...
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
1
answer
70
views
Failed to load ApplicationContext for my JUnit test
I followed an article about JUnit testing wrote a JUnit test for my User model:
import dev.cv.taskmasterserver.entity.User;
import dev.cv.taskmasterserver.repository.UserRepository;
import org.junit....
0
votes
0
answers
34
views
Log JUnit ClassOrderer Random Seed with Spring Boot and Logback
I am trying to log the JUnit ClassOrderer random seed using Logback, Spring Boot and Gradle. I found How can I make my JUnit tests run in random order? as related to my problem, but it uses the JUL ...
0
votes
2
answers
40
views
Mockito service dependency null pointer exception
So, let me show my problem. I have Service class:
@Service
@Transactional
public class UserServiceImpl implements UserService {
private final UserRepository userRepository;
private final ...
-3
votes
1
answer
83
views
Mockito Junit test case for while loop with break statement [duplicate]
I am writing Junit test case(Junit 5 with jupitar) for existing code that has while loop with break statement.
public int deleteRecords(int batchsize) {
//some code here
int totalDeletedRecords ...
0
votes
2
answers
136
views
How to mock HashMap in JUnit test in Spring Boot (Throws nullpointerexception)
I have a problem to write JUnit test for the method in my Spring Boot example shown below. I cannot handle with the mock implementation in HashMap in JUnit test as it throws null pointer execption in ...
0
votes
0
answers
94
views
Embedded Kafka Failed to Start After Spring Starter Parent Version 3.1.10
I'm trying to run some integration tests for Kafka consumer with,
org.springframework.kafka.test.context.EmbeddedKafka
Currently letting spring-boot-starter-parent to do the dependency version ...
-1
votes
1
answer
34
views
How to mock dependency in service class from Junit
I am trying to write the test cases of one of my service method. I am packing error like cannot invoke
Cannot invoke "com.company.app.models.Product.getId()" because "product" is ...
0
votes
1
answer
47
views
Autowire class's dependencies in jUnit without manual construction
My Service class has several autowired objects (Stored Procedures, SPs). Rather than a MockBean when/then, one test actually requires me to autowire the SP dependency objects in full, to see which ...
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/...