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

reload application context with all springboot test

I already add @SpringBootTest in all testcase. 'Run all test' in IDEA is OK, but when I use Maven test it didn't work. how to reuse context in Maven test commend. has any friend meet this problem? thx! my test case like this: @SpringBootTest class…
0
votes
0 answers

Spring Boot Integration Tests override custom .properties file

I am implementing integration tests and I have a problem with overriding custom properties that my application use. Integration test sample: @RunWith(SpringRunner.class) @SpringBootTest( classes = Application.class, webEnvironment =…
0
votes
1 answer

My Unit Test case fails with Assertion Error

Setup: spring-boot 1.4.3.RELEASE Java 1.8 I've written three test cases against my BluecostRestController.java (code below). The tests for the following URLs worked fine: GET /bluecost/sscdata GET /bluecost/sscdata/sergio Now I'm trying to write a…
JamesD
  • 679
  • 10
  • 36
0
votes
1 answer

Entities not scanned

I have a Maven project that represents the data layer of a single sign on (SSO) server. Other client applications shall rely on it for user authentication and authorization. It is a .jar archive that shall be used by another REST project, also a…
Stephane
  • 11,836
  • 25
  • 112
  • 175
0
votes
1 answer

Building maven spring boot project throws error

I am new to spring boot. I am trying to migrate project from old spring boot to the latest version. I changed the version of spring boot in project. But when i build the project it fails in tests throwing computational failure with error…
Neha
  • 745
  • 4
  • 10
  • 18
0
votes
1 answer

How to UnitTest JdbcDAOs in Spring-boot application

Our team just inherited a Spring-boot application (R1.4.3) which has the following pom.xml (excerpt): SpreadSheetUploadWeb SpreadSheetUploadWeb jar
JamesD
  • 679
  • 10
  • 36
0
votes
1 answer

SpringBootTest RestController in Spock Test results in 404

Given below code for Controller, when I start the spring boot application, I am able to make http calls to the resource /foo/id/{id} to fetch data. However the same call from an Integration test is returning 404. Call did not trigger rest controller…
suman j
  • 6,710
  • 11
  • 58
  • 109
0
votes
0 answers

How to skip JdbcAppender during @SpringBootTest?

We are using JdbcAppender to log all WARN and ERROR logs into database. But when we are running the SpringBootTest classes, we are using in-memory database for our tests so its throwing exceptions because of JdbcAppender fails to log. Caused by:…
Krish
  • 1,804
  • 7
  • 37
  • 65
0
votes
2 answers

Getting exception "Failed to load ApplicationContext" while running the test with Spring Boot and H2

I have a simple Spring Boot application that is using in-memory H2 DB. The initial data load is happening using schema.sql and data.sql. But I am getting exception after running test. pom.xml
Nital
  • 5,784
  • 26
  • 103
  • 195
0
votes
0 answers

spring-boot and mockito test - why is my test failing?

In the application I'm working now, I need to implement a few tests and build upon them. I've been reading and trying out a few things, but haven't had much success. The goal is to start back-filling with tests the service layer of the application.…
gtludwig
  • 5,411
  • 10
  • 64
  • 90
0
votes
1 answer

spring mongo query testing

I would like to set up a test (unit or integration test) for a mongo query. I would like to test the following function: public ArrayList search(){ Document textSearch = new Document("$text",new …
user1796624
  • 3,665
  • 7
  • 38
  • 65
0
votes
0 answers

Missing dependencies in SpringBoot2.0 unit tests

I´m trying to unit-test a SpringBoot application. Normal application execution works just fine, but I cannot execute my tests due to missing dependencies. I´ve tried many combinations of annotations and I´ve also experimented with the…
0
votes
1 answer

Testing with Springboot @autowire does not work with @SpringBootTest

I am writing Junits in springboot application , which has only one Initializer class as @SpringBootApplication public class Initializer extends SpringBootServletInitializer { @Override protected SpringApplicationBuilder…
Harsha
  • 87
  • 1
  • 14
0
votes
1 answer

Thymeleaf errors when doing mvc tests

I'm trying to test my controller that takes the form for updating supplier //get supplier form for update @GetMapping("/{id}") public String getSupplierUpdateForm(@PathVariable Long id, Model model) { …
0
votes
1 answer

How can I force @AutoConfigureJsonTesters to use HAL format from spring-hateoas?

I have a small module that should only contain the resource model of my REST service. I want to create a test in this module to ensure that the resource model serializes and deserializes appropriate HAL format. I have a single test and this is the…