Questions tagged [spring-test]

`spring-test` is the testing module of the Spring Framework, providing support for unit and integration testing with JUnit and TestNG, including various mocks for unit testing and the Spring TestContext Framework & the Spring MVC Test Framework for integration testing Spring-based applications.

Filter by
Sorted by
Tagged with
-1 votes
0 answers
22 views

Unit testing the new spring RestClient [closed]

with RestTemplate I use Spring's MockRestServiceServer to unit test my code, does spring have a similar Mock server for RestClient? Or do you have an example of testing RestClient in the wiremock ...
Tony's user avatar
  • 49
0 votes
1 answer
21 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
1 answer
13 views

What does Spring Boot test default configurations warn "Parameter 'systemProperties' is deprecated"?

In a Spring Boot test, when I annotated with @SpringBootTest, I get warning: Parameter 'systemProperties' is deprecated: Use systemPropertyVariables instead. Why is that and how can I fix it? This ...
SydMK's user avatar
  • 447
0 votes
0 answers
29 views

H2 Database runs sql scripts multiple time

I use the h2 database for repository unit testing , ı run the test cases as a class then scripts run multiple time. if i run the as one function then run normnally. I am doing unit testing to ...
enesergen's user avatar
0 votes
1 answer
37 views

Exclude spring.factories dependencies for Spring Boot test

There is one parent project A and the project which is using A's dependencies let's called it as B. Everything is working fine except testcases. I am using SpringBootTest which is fetching all the ...
Sakshi's user avatar
  • 9
0 votes
1 answer
66 views

How do I mock a method in another Service in Spring Boot

For context, I have 2 Service classes: ValService and AppService. In ValService I have a method validatewhich calls a method in AppService: Character c = appService.sendToAPI(listOfString, stringId); ...
titania's user avatar
  • 43
0 votes
0 answers
29 views

Junit5 Optimistic locking exception

I have nearly 1000 test classes coded using spring boot junit5. These run in parallel on Jenkins. Since my 6 test classes use the same table, I am getting optimistic lock errors and I could not find a ...
programmer's user avatar
0 votes
0 answers
21 views

No data received from WebTestClient when getting data from JpaRepository

I have a simple integration test case where I'd like to find a certain data. First, I use .save() to insert a data. While it works successfully (as I debugged it and also this.dataRepository.findAll() ...
Steven Kristian's user avatar
-1 votes
0 answers
22 views

how to solve the junit error which occured during running a springboot test application?

When I run the SqlcheckApllicationTests file as Junit I'm getting the below error .Please help me to rectify this error Image of the Error I tried to run SqlcheckApplicationTests file as Junit, the ...
Navya Hebbar's user avatar
0 votes
0 answers
46 views

Unable to Save in @SpringBootTest when using Transactional

I'm trying to create a simple integration test where I'd like to find a specific data using @RestController @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK) @...
Steven Kristian's user avatar
0 votes
0 answers
16 views

Spring Boot test and overriding the value of a private member

I am writing a spring boot test, but I use the annotation @Test I am able to create a bean that has an annotation @Autowired. This bean has a private data member like below @Value("${producer....
curiousengineer's user avatar
0 votes
1 answer
19 views

SpringJUnitConfig configuration class

I got lost when I'm trying to understand @SpringJUnitConfig. I know that @SpringJUnitConfig is a combination of @ExtendWith(SpringExtension.class) and @ContextConfiguration. However, I don't get in ...
Steven Kristian's user avatar
0 votes
1 answer
43 views

Why can't @SpringBootTest find any beans after Spring Boot 2 upgrade?

I am currently trying to upgrade a large Java 8 project from Spring Boot 1.5 to Spring Boot 2.7 (yes, very late to the party, I know). One thing I can’t figure out is that @SpringBootTest in SB2 seems ...
Tom Chatt's user avatar
0 votes
1 answer
79 views

How do I ensure my @Sql queries are shown in my console log?

Here's an MRE: package com.example.h2_demo; import org.junit.jupiter.api.Test; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.test.context.jdbc.Sql;...
Kodigas's user avatar
  • 55
0 votes
0 answers
20 views

Spring Boot RestTemplate call in test class doesn't work in second method

This is my RestUtil class import org.springframework.boot.web.client.RestTemplateBuilder; import org.springframework.http.HttpEntity; import org.springframework.http.HttpMethod; import org....
SmokingTurtle's user avatar
0 votes
1 answer
78 views

"More than one row with the given identifier was found". The problem: it's not an identifier

Note. It's a heavily trimmed down version of the problematic code. I spent a lot of time making it. I believe it's pretty MREish. I do hope for a helpful answer Here's my test package by.afinny.credit....
Kodigas's user avatar
  • 55
0 votes
0 answers
25 views

WebFluxTest doesn't resolve requests to controller, if controller implements interface

There's Spring/Webflux-based REST API server in Kotlin. All was OK, when there was just a controller. and the test was working. But when I changed controller to implement interface, the WebFluxTest ...
Victor Mikhailov's user avatar
0 votes
1 answer
48 views

Spring Boot not-decoding special characters inside URL Parameter when running Integration Tests

I have a GET Endpoint in the Spring Boot RestController that is accepting an email as a URL Parameter ( I know this is not so good idea, but I cannot change this as of now). EmailController.java ...
Sai Upadhyayula's user avatar
0 votes
0 answers
14 views

Spring automatically uses fastTime instead of Date?

I have a Spring Boot test in which I perform get request for a resource and I am checking then the returned JSON, however when dates are being returned I have the fastTime instead of the actual Date ...
Lia's user avatar
  • 15
0 votes
1 answer
111 views

Adding JUnit test suite to a Spring MVC application

I want to add JUnit test suite to an already up-and-running spring mvc application. In particular I want to test the Controllers APIs. Is there a particular procedure you can recommend? I dont' want ...
Giuseppe's user avatar
0 votes
2 answers
56 views

Spring test @Sql throws "Unterminated dollar quote started ... Expected terminating $$"

I am testing my Spring Boot API with a test class (FoodE2eTest) and I have a separate SQL script file (setup-test-schema.sql) that I want to run before the tests start to set up schema, tables, and ...
Siim Karel Koger's user avatar
0 votes
0 answers
42 views

Mocked Rest Service throwing 500 InvocationTargetException after Expected Exception since Spring Boot 3

I have a Spring Boot project I recently upgraded to 3.0. Ever since the upgrade I am getting a failed integration test. @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) ...
user2725919's user avatar
1 vote
0 answers
25 views

Prevent configuration properties binding in Spring test

I have the following configuration class: @ConfigurationProperties(prefix = "xyz") @Validated public class AppConfiguration { @NotNull private Path path; } And I'm trying to create ...
Simon's user avatar
  • 41
0 votes
0 answers
18 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
0 votes
0 answers
30 views

Creating @RestClientTest test without @SpringBootTest gives error : "java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration"

I would like to create a Unit Test for a class which has dependency on RestTemplate and is doing REST calls: public class SOClient { private final RestTemplate restTemplate; ... // ...
fascynacja's user avatar
  • 1,785
-1 votes
2 answers
53 views

JPA repository with modified query. How to test it?

I have no experience. I started to study testing. Is this repository correct? How to test it? public class Person extends Auditable<String> implements Serializable { @Id @Tsid ...
Makkambaev Dastan's user avatar
1 vote
1 answer
20 views

How can I fix a RestDocumentationGenerationException: java.io.FileNotFoundException: /curl-request.adoc (Read-only file system) in my Spring Boot app?

Would you believe googling this returned a whopping two results! I'm trying to use Spring REST Docs (spring-restdocs-mockmvc) to generate API documentation for my service. Running on a macbook pro ...
mal's user avatar
  • 3,090
0 votes
1 answer
59 views

Spring Test Mapper Return Null

I am writing test unit for my backend project. Also I am using ModelMapper for map functions. But when I write getAll() or update() etc. at test method from manager ProductManager, Spring says org....
Hakan's user avatar
  • 23
1 vote
1 answer
84 views

How to mock configuration class for test

I am facing with NPE. I am writing test for my credential class but I am facing with NPE error. Here is my test class @ExtendWith(MockitoExtension.class) public class CredentialServiceTest { @...
Serdar's user avatar
  • 349
0 votes
0 answers
32 views

Failed to load ApplicationContext while running AppTest.class in java spring project

I'm writing spring web-program. After I wrote controllers,mappers and so on I need to test them. Before this I just tried to run my BankAppApplicationTests.class that was generated automatically, ...
Vitalii's user avatar
  • 11
1 vote
1 answer
42 views

How can I exclude test classes when running nativeTest?

I have a Spring boot 3.1.4 application that has some tests that use things like @DataJpaTest/@WebMvcTest/etc that use mocking & whatnot which aren't supported when running in native test mode. Is ...
Eric's user avatar
  • 374
0 votes
0 answers
20 views

Creating test objects for testing purposes without boilerplate code in spring boot

I am dealing with boilerplate code in my test cases. I use JUnit and Mockito as frameworks for my tests. I am building a rest API and when a create request for example performs from client I get this ...
user14800584's user avatar
1 vote
0 answers
23 views

Run minmal Spring Boot test with enabled selected factory/processor

To the testing of logging I need to activate LogbackLoggingSystem processor or corresponding factory: # Logging Systems org.springframework.boot.logging.LoggingSystemFactory=\ org.springframework.boot....
gavenkoa's user avatar
  • 46.1k
-1 votes
1 answer
86 views

Mockito 5.x.x fails Junit tests due to mock interaction inside log method

After upgrading to Mockito 5.x.x, test cases started failing showing interactions on mocks, mentioned inside log message. Prior to Mockito 5.x.x, the below code was working fine. @Test void name() ...
Manu's user avatar
  • 3,495
0 votes
0 answers
30 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>> ...
coder87's user avatar
  • 147
2 votes
2 answers
227 views

How to replace bean for particular test in SpringBootTest?

I want to avoid connection to Ldap in my integration test so I've added mock of LDAPConnectionPool so I have a test class like this: @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment....
gstackoverflow's user avatar
0 votes
0 answers
65 views

@WebMvcTest doesn't work properly (401 and 404 errors)

Note: this is solved, but it's worth being here, as I think it can help a lot of people. Also, some of the code is in spanish because that's my first language. So, let me start by bitching. I think ...
Gonzalo Martinez's user avatar
0 votes
0 answers
62 views

Fail to instantiate Java Record annotated with @ConfigurationProperties

I was trying to use Java Record as a Configuration Property whose fields like url,username and password comes from external properties file. For this, I have following code: @...
Sudhir Kumar's user avatar
-1 votes
1 answer
99 views

How to "Autowire" repository in JUnit 5 test

I don't understand yow to refer to my services/repositories in a JUnit 5 test. I'm trying to annotate it the same as I do my Main class which runs fine: @ComponentScan @EnableJpaRepositories @...
Gaetan L.'s user avatar
  • 615
0 votes
1 answer
218 views

No qualifying bean of type 'org.springframework.batch.core.configuration annotation.JobBuilderFactory' available: in Junit

I went through below few links already, but did not turn to be working, I'm using Spring Boot v2.7.1 and Batch and has below code and using junit 5. https://docs.spring.io/spring-batch/docs/4.0.x/...
Prateek's user avatar
  • 10.9k
0 votes
0 answers
20 views

How do I mock authentications when doing @WebMvcTests with filters enabled?

I tested this controller class @RestController public class MyRestController { private final UserService userService; private final PasswordEncoder passwordEncoder; public ...
JoreJoh's user avatar
  • 321
0 votes
1 answer
57 views

When and how exactly does @SpringBootTest scan?

How exactly does @SpringBootTest scan? My current understanding is this: If you pass a @Configuration, it doesn't scan at all and is happy with that configuration class's beans If you don't pass any ...
JoreJoh's user avatar
  • 321
0 votes
1 answer
43 views

ObjectMapper doesn't map JSON's String to ZonedDateTime

I am writing Integration tests with MockMvc and want to receive my Response as an Object in order to make assertions on it. The line AuthenticationResponse authenticationResponse = objectMapper....
ZZBL's user avatar
  • 15
0 votes
0 answers
37 views

@MockBean on a MapStruct interface in a Spring @WebMvcTest does not work

Given the following controller in a Spring Boot 3 application: // REST controller class @RestController @RequestMapping("/bookings") @RequiredArgsConstructor class BookingController { ...
Robert Strauch's user avatar
0 votes
0 answers
398 views

java.lang.NoSuchMethodError with Junit5 in SpringBoot app

I was attempting to add some Parameterized unit tests to an app that I'm adding some enhancements to, but ran in to errors when attempting to launch JUnit once I added @Parameterized tests. I've found ...
WishIWasJeeping's user avatar
0 votes
2 answers
41 views

Resetting the H2 incrementer

How do I reset the id incrementer in H2? Call it an XY problem, if you want, but my test fail just because the ids (GenerationType.IDENTITY) don't match. I clear the rows in @BeforeEach, but the ...
JoreJoh's user avatar
  • 321
0 votes
0 answers
34 views

Mocking RestTemplate that uses OkHttp3ClientHttpRequestFactory using Mockito

I have a method that needs testing but I am having trouble mocking it. void updateData(String testData){ RestTemplate testRT = new RestTemplate(new OkHttp3ClientHttpRequestFactory); HttpEntity&...
justAGuy's user avatar
0 votes
0 answers
27 views

Testing a method that returns a list which created by an inner method call inside a stream

I have this method under test @Override public List<LeaveResponseEntity> fromLeaveListToAdminHrMngLeaveList(Set<Leave> leaveList) { return leaveList.stream().map(this::...
user14800584's user avatar
0 votes
0 answers
32 views

Tracer not getting initialized through constructor when running Junit test case in Spring Boot

I am trying to run a Junit test from spring boot and added the AvailabilityController with @InjectMocks. Controller has a constructor which takes Tracer(brave.Tracer) as one of the argument. So have ...
Sbas's user avatar
  • 1
0 votes
0 answers
18 views

Junit test for suscription mapping not working

I have been referring to this https://docs.spring.io/spring-graphql/docs/current/reference/html/#testing to setup test for the subscriptionMapping However when I run the test the subscription start ...
Utkarsh Sharma's user avatar

1
2 3 4 5
42