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

Maven Spring boot: set additional properties file location on test

Currently, I'm setting additional spring boot properties file using spring.config.additional-location: mvn -DskipTests spring-boot:run -Dspring-boot.run.arguments=--spring.config.additional-location=api-props.properties I'd like to know how to set…
Jordi
  • 20,868
  • 39
  • 149
  • 333
0
votes
1 answer

Spring Boot ComandLinerRunner Test

I have a question Sample Class @SpringBootApplication(scanBasePackages = { "com.Sample.smartbuy" }) public class SmartBuyArtApi2ClientApplication implements CommandLineRunner { public static final Logger logger =…
0
votes
0 answers

How to write Spring boot test cases in multiple files for multiple controller respectively

I am using JUnit and Mockito to write test cases for Spring Boot Application. I have multiple controllers(For eg: ContractController and CountryCOntroller). When I write test cases for both of them in a single file , test will pass but if I write…
Veda
  • 577
  • 1
  • 6
  • 22
0
votes
1 answer

ModelAndView returns null SpringBootTest

I am trying to learn junit tests using spring boot. Normally i wouldnt just ask null pointer exception but now i couldnt find what is missing. @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment =…
Neo
  • 467
  • 1
  • 3
  • 17
0
votes
1 answer

How to resove java.lang.IllegalArgumentException: Property 'dataSource' in Junit for Springboot Rest

The error is thrown while trying to unit test the Service class that contains an autowired Dao object which internally uses an Autowired JdbcTemplate in Spring boot Rest service using Junit and Mockito
Arun
  • 1
0
votes
1 answer

Null Pointer Exception while calling a RestController using Mockmvc perform() method in SpringBoot

I am using MockMvc for the first type. What I am doing is testing a Restcontroller in SPringboot. I have a Restcontroller like this, @RequestMapping("/address") public class AddressController { @RequestMapping("/createAddress") …
0
votes
1 answer

Cannot use spring's embedded message broker for test

I have following component which is using for sending messages to broker (kafka) and also receiving by StreamListener of spring-cloud. Now I need write test where I send message to embedded broker and also I verify that message is received. Here is…
0
votes
0 answers

Dynamically loading environment property for flow testing in spring integration

I am trying to test the flow of a spring integration XML that I built. I am using a Custom Transformer class to write my own transformation in which I am setting the profile based on the property. This property is set to dev in…
0
votes
1 answer

ContextRefreshedEvent fired too early in Spring integration test

I want to test a class like Example that handles a ContextRefreshedEvent and connects to a server in the handler method: public class Example { @EventListener public void onApplicationEvent(ContextRefreshedEvent event) { …
deamon
  • 89,107
  • 111
  • 320
  • 448
0
votes
1 answer

@BeforeStep method is not called during unit test execution

I have an ItemProcessor which has a @BeforeStep method to access the ExecutionContext: public class MegaProcessor implements ItemProcessor { private ExecutionContext context; @BeforeStep void getExecutionContext(final…
yN.
  • 1,847
  • 5
  • 30
  • 47
0
votes
1 answer

Ignore to load XML file from SpringBootApplication

I have a Spring Boot application structure like this: src/main/java /main/Application.java src/main/resource/ /application-context.xml src/test/java /main/TestApplication.java src/test/resource/ …
Ryo
  • 995
  • 2
  • 25
  • 41
0
votes
0 answers

How To Consume OAuth2 Protected REST Services: Using github

I am writing java based client application which has to connect to the web application which is protected with oAuth2. I want to use grant type as "password" which is to be authenticated with GitHub. Here is my…
0
votes
0 answers

Spring-boot with HSQLDB Integration tests

We have spring-boot-starter-parent 1.4.3.RELEASE as the base for our simple RESTful application. IBM DB2 10.5 is our runtime db We are using HSQLDB embedded database for our DAO unit tests and that's working fine. We have Unit Test cases with…
JamesD
  • 679
  • 10
  • 36
0
votes
0 answers

InterruptedException and TaskRejectedException in SpringBootTest with Async service

I am testing using SpringBootTest. One of the services behind uses an asynchronous service running with an Executor service that has 50 threads. But I am getting Shutting Down ExecutorService asycnExecutor, InterruptedException then…
Dexters
  • 2,419
  • 6
  • 37
  • 57
0
votes
1 answer

Caused by: java.lang.ClassNotFoundException: javax.servlet.ServletException

when i am trying to run the controller Testing in Spring-boot version 1.5.3 Release using the Spring-Boot-Test I am geting the Error Caused by: java.lang.ClassNotFoundException: javax.servlet.ServletException import static…
Prabhat Yadav
  • 1,181
  • 6
  • 18
  • 29