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

972 questions
41
votes
3 answers

SpringRunner vs SpringBootTest

In unit test, what are the differences between @Runwith(SpringRunner.class) & @SpringBootTest? Can you explain to me the use cases of each one?
zouari
  • 535
  • 1
  • 3
  • 12
28
votes
3 answers

SpringApplicationConfiguration not found: Erroneous spring-boot-starter-test content?

Getting a compilation error in Maven: [INFO] ------------------------------------------------------------- [ERROR] COMPILATION ERROR : [INFO] ------------------------------------------------------------- [ERROR]…
Simeon Leyzerzon
  • 17,374
  • 7
  • 44
  • 68
20
votes
2 answers

Testing a @KafkaListener using Spring Embedded Kafka

I am trying to write a unit test for a Kafka listener that I am developing using Spring Boot 2.x. Being a unit test, I don't want to start up a full Kafka server an instance of Zookeeper. So, I decided to use Spring Embedded Kafka. The definition of…
19
votes
1 answer
18
votes
3 answers

Spring Boot Unit Test a module not detecting an autowired component

we have split our Maven based Spring Boot project into two modules as…
Carmageddon
  • 1,765
  • 2
  • 24
  • 47
18
votes
5 answers

Unable to start ReactiveWebApplicationContext due to missing ReactiveWebServerFactory bean

I have a new springboot application I am attempting to get started. The error I receive is org.springframework.context.ApplicationContextException: Unable to start reactive web server; nested exception is…
Daniel Lynch
  • 203
  • 1
  • 3
  • 7
14
votes
3 answers

Resolving port already in use in a Spring boot test DEFINED PORT

I have a spring boot application that fires up and executes a class that listens to Application Ready event to call an external service to fetch some data and then use that data to push some rules to the classpath for execution. For local testing we…
ahjashish
  • 463
  • 1
  • 3
  • 12
13
votes
1 answer

How to use these @DataMongoTest and @SpringBootTest together in integration test

I am trying to write integration test case for one of my rest application which uses mongodb internally to persist the data @DataMongoTest @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) public class MainControllerTest…
kcoder
  • 1,701
  • 2
  • 18
  • 39
13
votes
1 answer

Spring boot test: context loaded for every test?

In my project we have a super class for all our tests. This is the signature of that class @RunWith(SpringRunner.class) @SpringBootTest(value = {"management.port=0"}, classes = Application.class, webEnvironment =…
Perimosh
  • 1,477
  • 2
  • 13
  • 28
13
votes
1 answer

Junit5 with spring-boot 1.5

I have a spring-boot application which uses spring-boot version 1.5.9.RELEASE. To test this application I want to use junit-jupiter version 5.0.2. For simple service tests it works without any problems. But when it comes to testing rest endpoints, I…
tgr
  • 3,309
  • 2
  • 30
  • 57
12
votes
3 answers

Difference between junit-vintage-engine and junit-jupiter-engine?

It's a two-fold question. What is the difference between junit-vintage-engine and junit-jupiter-engine? SpringBoot starter projects come with an exclusion for junit-vintage-engine. Is it to enforce the use of junit-jupiter-engine? Below is the…
Sandeep Kumar
  • 1,707
  • 4
  • 21
  • 31
12
votes
7 answers

JUnit's @TestMethodOrder annotation not working

I'm having a problem with following integration test import org.junit.jupiter.api.Order; import org.junit.jupiter.api.TestMethodOrder; import…
toucheqt
  • 525
  • 2
  • 6
  • 13
12
votes
2 answers

How to fix error from embedded kafka that cannot find meta.properties

I am trying to do integration test for app that using kafka, kafka-streams and cassandra. But when I am trying to setUp test class, i've got 2 errors: ERROR [main] BrokerMetadataCheckpoint: Failed to read meta.properties file under dir ERROR [main]…
faceoff
  • 133
  • 2
  • 8
12
votes
5 answers

How to prevent logging noise during startup in @SpringBootTest?

@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = "logging.level.root=OFF") public class MyTest { @Test public void test() {} } As a result of…
membersound
  • 66,525
  • 139
  • 452
  • 886
11
votes
3 answers

/actuator/prometheus missing in @SpringbootTest

I'm using springbooot 2.4.0 and I added the following dependencies for enabling prometheus metrics: org.springframework.boot
1
2 3
64 65