Questions tagged [spring-boot-test]

Spring Boot provides utilities and annotations to help when testing your application.

Spring Boot provides a @SpringBootTest annotation which can be used as an alternative to the standard spring-test @ContextConfiguration annotation when you need Spring Boot features. The annotation works by creating the ApplicationContext used in your tests via SpringApplication.

Utilities: ConfigFileApplicationContextInitializer,EnvironmentTestUtils,OutputCapture and TestRestTemplate

for example

EnvironmentTestUtils.addEnvironment(env, "org=Spring", "name=Boot");

Docs: https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-testing.html

1399 questions
0
votes
1 answer

Spring JPA Test still connects to database on start up or not?

Id like to ask whether spring boot jpa test still needs to connect first to database before starting the test or not? if not so it just uses the in-memory embedded database? I am migrating a legacy app and its part of the test requirement (unit…
mark ortiz
  • 659
  • 1
  • 6
  • 13
0
votes
1 answer

Inconsistent run of springboot application when run in Eclipse

I have observed an inconsistent way properties are being read in Eclipse. I have a very simple Springboot web project with typical property files. Here is my project layout: Notice the two property files: testapplication.properties and…
0
votes
2 answers

Is a mock MongoRepository saving objects?

I am using SpringBoot 1.5.9 and try to do Integration testing. Weirdly a MongoRepository.save() method updates the object when called on mock MongoRepository. I have a Counter Class public class Counter { public String id; public int…
0
votes
2 answers

Using orm.xml in tests of SpringBoot 2.0

I have a SpringBoot 2.0 application, and I've decided to mix annotations and XML configuration using orm.xml. So, I've put orm.xml (JPA file with XML configuration) in resources/META-INF, and, when starting the application, it's taken into account…
Vlad Dinulescu
  • 1,173
  • 1
  • 14
  • 24
0
votes
1 answer

@WebMvcTest for SOAP?

Is the Spring Boot annotation @WebMvcTest only intended for sliced RestController tests or should SOAP Endpoints be testable with it too? When I setup my test and run it, I only get a 404 response as if the endpoint wasn't there so I assume it…
user3105453
  • 1,881
  • 5
  • 32
  • 55
0
votes
0 answers

Parallelising DB integration tests - java, spring

I have a suite of tests that make db calls (via spring-data-jpa) and assert the result against an in memory database (mariadb4j). Before every test, it restarts the spring context providing me with a new spring context and database every time and I…
Ali H
  • 362
  • 7
  • 19
0
votes
1 answer

When to use @IncludeEngines and when to use@ExtendWith of Junit5

Please support me in understanding and over coming confusion of when to use @IncludeEngines and when to use @ExtendWith in JUnit 5. Apologies if this question is too basic. Thank you in advance.
0
votes
0 answers

How to test multiple data sources in single application?

I have a spring boot application, which is connecting to two different data sources. (All the connection, URL, other DB properties are different and configure in application.properties file) I am not able to test this application because mockito or…
0
votes
1 answer

Using SQL database for running tests in Jhipster

I have configured the test application properties to use Postgresql. All tests seem to work but that is not totally correct. When I do actual persistent data tests, there is no data being saved to the postgresql db even though liquibase is…
0
votes
1 answer

Unit testing of Spring ApplicationEventPublisher fails to consume the events

I want to integration test a Spring Boot 1.5.4 service that uses an @EventListener. My problem is: when the test is run, the events are correctly published, but they are not consumed. My ultimate purpose is to use a @TransactionEventListener, but…
Ivan dal Bosco
  • 3,233
  • 4
  • 19
  • 24
0
votes
0 answers

Use spring.profiles.active=@profileActive@ in property file of test/resource folder

In my application I have three different profiles and their own property files. In my application.properties file the correct active profile will be set by the profile of my maven build: spring.profiles.active=@profileActive@ The maven profiles are…
Patrick
  • 12,336
  • 15
  • 73
  • 115
0
votes
1 answer

Spring Data Cassandra not mapping JSON Request if key of POJO is composite

I am trying to save a request to Data Stax-Cassandra. Components: EventController:@RestEndPoint OneKeyClass:For Complex Key(with multiple columns) I am using Standard Spring Repository Model to save and fetch the data. Gradle: plugins { id…
0
votes
0 answers

What's the correct way to write a Spring Boot Integration Test for REST API

I have a REST API developed using Spring Boot and H2 DB which is working fine without any issues. http://localhost:8080/api/employees returns [ { "id":1, "name":"Jack" }, { "id":2, "name":"Jill" } ] Now the…
Nital
  • 5,784
  • 26
  • 103
  • 195
0
votes
1 answer

java.lang.NoSuchMethodError when running SoapUIMockServiceRunner

Ran into an issue while running a SoapUI MockService in my integration tests for our Spring Boot project. static SoapUIMockServiceRunner mockServiceRunner; @BeforeClass public static void setupSoapUI(){ mockServiceRunner = new…
Denn0
  • 377
  • 3
  • 15
0
votes
0 answers

Spring boot Test class annotation error

Each time I create a new project with spring boot 1.5.8, there has an error with test class annotation. When I remove the test class and dependency, project run perfectly. There was problems with @Test annotation, I fixed that adding a Junit4…