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
5
votes
1 answer

Spring-boot Test to load external jars (equivalent of loader.path)

We have an application which has runtime dependencies on external jars (e.g Talend jobs running within Spring-boot). Now we're able to get this launched from Spring-Boot using the -Dloader.path argument. However, we're unable to run integration-test…
Jebuselwyn Martin
  • 543
  • 1
  • 5
  • 18
5
votes
2 answers

Is it possible to activate a spring profile in a WebMvcTest

Given a test class like: @WebMvcTest @RunWith(SpringRunner.class) @SpringBootTest(properties = "spring.profiles.active=test") public class MyControllerTest { ... some tests } I get the error: java.lang.IllegalStateException: Configuration error:…
David
  • 7,652
  • 21
  • 60
  • 98
5
votes
3 answers

Spring boot: @ConfigurationProperties not satisfied on test

I'm getting this exception on my test excution: UnsatisfiedDependencyException: Error creating bean with name 'net.gencat.transversal.espaidoc.mongo.GridFSTest': Unsatisfied dependency expressed through field 'resourceProperties'; nested exception…
Jordi
  • 20,868
  • 39
  • 149
  • 333
5
votes
4 answers

Junit5 Spring Boot Autowire ComponentScan Not Working

My problem: if my test refers to an @Bean declaration in the class listed in @SpringBootTest, autowire works. If it refers to a class automatically @ComponentScanned by the class listed in @SpringBootTest, autowire fails. Outside of testing, my…
billmill
  • 331
  • 1
  • 3
  • 14
5
votes
3 answers

How to forward the local port of a SpringBootTest to a test configuration

I am currently struggling with the server port injection of the SpringBootTest instance. I've written a test configuration class where I would like to access this port. Test Configuration class: @Target(AnnotationTarget.CLASS,…
5
votes
2 answers

Test for Spring Boot @ConfigurationProperties validation fails

I want to write a test for a @NotNull, @NotEmpty validation of @ConfigurationProperties. @Configuration @ConfigurationProperties(prefix = "myPrefix", ignoreUnknownFields = true) @Getter @Setter @Validated public class MyServerConfiguration { …
TanjaMUC
  • 61
  • 4
5
votes
1 answer

How to integrate Spring Boot, Cucumber and Mockito?

There are ways online to integrate Cucumber with Spring Boot. But I cannot find how to do so with Mockito also. If I use the Cucumber runner and annotate the steps file with ContextConfiguration and SpringBootTest, the container injects the…
Roger Gouveia
  • 431
  • 5
  • 7
5
votes
0 answers

Springboot 2 Could not initialize plugin: interface org.mockito.plugins.MockMaker

Currently I test the new version of springboot 2. I created a @controller and the associated test by following the doc provided. But when I run the test, I always get the following exception: 2018-04-30 21:02:49.536 WARN 13584 --- [ main]…
Régis Le Coz
  • 71
  • 1
  • 3
5
votes
2 answers

Testing Neo4j with Spring Boot and embedded driver

Problem I build an application using a Neo4j database. I like to test some custom Cypher queries using Spring Boot's @DataNeo4jTest annotation (see also Spring Boot Test - Neo4j), but I run in either one of the following problems: The test tries to…
Marian
  • 351
  • 2
  • 12
5
votes
2 answers

Adding configuration class to SpringBootTest breaks component scan

I am trying to disable real Mongo connection and replace it with Fongo mock in tests. Here is my test class: @SpringBootTest @RunWith(SpringRunner.class) public class ControllerTest { @Autowired private…
Alesto
  • 639
  • 4
  • 13
  • 29
5
votes
1 answer

Execute the same @SpringBootTest with different properties

I have a @SpringBootTest which is used to execute an integration test on the server. Depending on the configuration I want the server to behave differently. The configuration itself is read by beans (scope = singleton) deep inside my app logic and…
smigfu
  • 855
  • 1
  • 6
  • 9
5
votes
1 answer

Confused about Spring boot test specific @TestConfiguration

According to Spring Boot Docs, a nested @TestConfiguration should be detected by tests automatically. But in my test codes it is problematic when I ran the whole test class, it was not detected even I added it explicitly by @Import. The test code…
Hantsy
  • 8,006
  • 7
  • 64
  • 109
5
votes
1 answer

Speed up startup time of a SpringBootTest with SpringRunner

I am looking for a way to minimize startup time of a SpringBootTest which currently takes up to 15 seconds until it is started and tests are executed. I already use the mocked webEnvironment and the standaloneSetup() of the specific RestController…
user3105453
  • 1,881
  • 5
  • 32
  • 55
5
votes
0 answers

Spring Boot Test is not loading classes with @Component annotation

In my Spring Boot Application, I am writing integration tests using @SpringBootTest. I am using a config class for Configuration and used @ComponentScan on it but it's not loading components and tests are…
Harshit
  • 1,334
  • 1
  • 9
  • 23
5
votes
2 answers

How to exclude ApplicationContextInitializers in @SpringBootTest?

I'm trying to run a @SpringBootTest in a "clean" context without having MyApplicationContextInitializer executed. The MyApplicationContextInitializer is included inside the spring.factories file in a compile-scope dependency like…
eremic
  • 113
  • 9