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
2 answers

Spring boot - tests for servlet request/response, how to inject mock classes?

I'm quite new to spring boot and got a basic microservice put together (It accepts a Yelp url and scrapes the images for that restaurant). I thought it would be a good time to write some unit tests, but one thing I'm having trouble with is injecting…
girbic
  • 301
  • 3
  • 11
0
votes
3 answers

Spring Boot Camel Test

I am writing a test for Camel using Spring boot. Below is configuration on the test class @RunWith(CamelSpringBootRunner.class) @SpringBootApplication @ComponentScan(basePackages =…
AMK
  • 3
  • 3
0
votes
1 answer

code to run before @Autowired is happening

I want to run some lines of code before this line runs: @Autowired private SomeClass a; I'm working on a testing class, I tried @Before, but the @Autowired runs before the code in the @Before, so there is another solution to run code before the…
T.S
  • 911
  • 8
  • 24
0
votes
1 answer

integration tests on Java, SpringBoot, gradle to exclude from build

How to exclude integration tests on Spring Boot test, gradle based on external properties? tried with @ActiveProfiles. But it did not work
shabinjo
  • 1,473
  • 1
  • 16
  • 22
0
votes
1 answer

Spring Boot multiple module test Autowiring

I have a multiple module project with structure: app/ build.gradle settings.gradle app-web/ src/main/java/example/ Application.java app-repository/ src/main/java/example/ CustomerRepository.java Customer.java …
Eduardo
  • 6,900
  • 17
  • 77
  • 121
0
votes
1 answer

In intelliJ Run/Debug Configuration, how to skip spring boot tests

We have written tests using annotations like below, @RunWith(SpringRunner.class) @Slf4j @SpringBootTest in IntelliJ 2017 we run spring boot program via Run/Debug Configuration, and it automatically execute these tests. But some tests really takes a…
Sai
  • 73
  • 1
  • 10
0
votes
1 answer

Spring cloud contract PCF dependencies

To test spring boot micro services deployed in PCF environment, our team started implementing spring-cloud-contract framework. To explain my problem, we have two microservices A and B and A is consuming B service. I have developed contract at B and…
0
votes
1 answer

MultipartFile upload test in Spring Boot Failing - not sure why

I'm testing a POST method in a controller that handles the uploading of an image via a MultipartFile. It is allowed to be empty, but if there is a file present, it should upload it. I wrote a Unit test to make sure it worked, but the test is…
NateH06
  • 3,154
  • 7
  • 32
  • 56
0
votes
0 answers

Can't Spring custom auto configuration class have the same name as default auto configuration class

I'm trying to write a custom auto configuration class to override the behaviour of default auto configuration class. For instance, imagine I'm trying to override the behaviour of…
Manikdn84
  • 357
  • 4
  • 21
0
votes
1 answer

Spring Boot tests - posted content is null with @WithMockUser

I am trying to test my CommentController with a @WithMockUser test, but it seems like it does not find either the user(since the user id (author_id) is null) or content of the comment. I am not sure if the test is done the right way (I am still a…
user3285241
  • 319
  • 2
  • 3
  • 18
0
votes
1 answer

FTP Route - Unit Testing

I have a camel route which: polls a FTP server for new XML files downloads the files locally validates the XML files against a XSD splits the XML by categories into entities transforms the entities into json sends the json to a HTTP…
eistropfen
  • 35
  • 6
0
votes
1 answer

Spring Boot Integration Testing

I have been trying to write a integration test for a small Spring boot Project that I have written but for some reason seem unable to get integration tests to work. Here is what I am trying to do: package au.azzmosphere.integration; import…
0
votes
2 answers

How to test domain event in Spring Boot @DataJpaTest?

I'm using Spring Data JPA domain event as described in https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#core.domain-events. The event listener is marked with @Service. It is working perfectly when I run it, but I can't make it…
a20_umb
  • 23
  • 1
  • 5
0
votes
1 answer

Spring Boot 2 M3 - MyBatis 1.3.0 - Test - Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required

I'm encountering the following error only when running Test class. This occurs only with Spring Boot 2 (M3 for now), while it's OK with Spring Boot 1.5.3. MyBatis 1.3.1-SNAPSHOT seems not available/published, so I use…
Davideas
  • 3,226
  • 2
  • 33
  • 51
0
votes
1 answer

@DataJpaTest and @Async CRUDRepository method not working together

I'm currently implementing a few repository methods as @Async with spring-boot, and it's working like it should when i actually boot up the application, but when running integration tests, things starts to act weird. I have setup a little project…
Martin Hansen
  • 2,033
  • 1
  • 18
  • 34