Questions tagged [spring-test]

`spring-test` is the testing module of the Spring Framework, providing support for unit and integration testing with JUnit and TestNG, including various mocks for unit testing and the Spring TestContext Framework & the Spring MVC Test Framework for integration testing Spring-based applications.

spring-test is the testing module of the core Spring Framework, providing support for and and based applications with and , including mocks for things like the and APIs, the Spring TestContext Framework, and the Spring MVC Test Framework.

Online Resources:

Related Tags:

2041 questions
11
votes
1 answer

Configuration properties are not loaded in Spring Test

I have a Spring Boot application which has some configuration properties. I'm trying to write a test for some of the components and want to load configuration properties from a test.properties file. I can't get it to work. Here's my…
lexicore
  • 42,748
  • 17
  • 132
  • 221
11
votes
1 answer

Writing tests to verify received msg in jms listener (Spring-Boot)

I want to write test for something like below; There is a listener called state-info-1 in src/main. It does some changes to any message it gets and publishes the new message on activemq topic state-info-2. I will build a dummy message and publish…
Rajkishan Swami
  • 3,569
  • 10
  • 48
  • 68
11
votes
0 answers

MockBean in SpringBootTest depends on executing order despite DirtiesContext.ClassMode.BEFORE_CLASS

Given the following class definition: @RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, classes = Application.class) @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS) public class…
Florian
  • 1,827
  • 4
  • 30
  • 62
11
votes
1 answer

Asserting list of return items from Spring Controller with mockMvc

I've set up a spring boot application to use a Spring MVC controller to return a list of items. I have a spring test that creates a mocked dependency that gets wired in to the Controller, and the controller returns the list of expected mocked items…
Stealth Rabbi
  • 10,156
  • 22
  • 100
  • 176
11
votes
4 answers

How to one-off run @DataJpaTest against real database instead of in-memory with Spring Boot

I am using Spring Boot 1.4.3 and have a whole bunch of tests that are annotated with @DataJpaTest. By default, they run against an in-memory database. I would like to be able to run all of them against a local MySQL temporarily. How can I do this in…
Wim Deblauwe
  • 25,113
  • 20
  • 133
  • 211
11
votes
4 answers

Junit Tests with Spring Boot Actuator gives Exception

When I enable Actuators in my Spring Boot application, my Junit tests failed with a NullPointer Exception. The actuators are working fine, and the tests were working fine before I added the actuator artifact in my pom.xml file. Seems like the…
Leamas
  • 385
  • 3
  • 14
11
votes
1 answer

Replacement of import org.springframework.test.context.transaction.TransactionConfiguration; in Spring Test 4.3.1 version?

I'm working on the JPA QueryDSL example. In this example I created PersonDaoTest.java. Earlier I was using the lower version of spring-test as client asked to update it its latest version so I used 4.3.1.RELEASE. When I used this version I see that…
user4821194
11
votes
3 answers

JUnit 5 - Empty test suite in IntelliJ IDEA when using JUnit Jupiter engine

How to execute All Suite tests with JUnit 5 in IntelliJ IDEA v2016.2.2? I get Empty test suite running this code: import org.junit.platform.runner.IncludeEngines; import org.junit.platform.runner.JUnitPlatform; import…
Davideas
  • 3,226
  • 2
  • 33
  • 51
11
votes
3 answers

Spring Boot Integration test random free port

I am able to get Spring Boot integration to generate a random free port to launch itself on. But I also need a free port for Redis. @ContextConfiguration(classes = {MyApplication.class}, loader =…
ptimson
  • 5,533
  • 8
  • 35
  • 53
11
votes
6 answers

Spring MVC Test empty json

How can I test for an empty JSON response from a rest endpoint. I was hoping for something along the lines: ResultActions actions = mockMvc.perform(..); actions.andExpect(jsonPath("$", empty())); obviously this fails as {} is not exactly…
Suryavanshi
  • 595
  • 1
  • 7
  • 24
11
votes
3 answers

JUnit Tests: Why is Maven (Surefire) so much slower than running on Eclipse?

I'm working on a fairly big application, with ~260k LOC and roughly 1800 unit tests on the suite. A little background: Multi-modular Maven project All tests run on a separate module and JaCoCo is used to check coverage. Tests are put together in…
Gustavo Ramos
  • 1,324
  • 1
  • 12
  • 23
11
votes
3 answers

Spring Boot @WebIntegrationTest and TestRestTemplate - Is it possible to rollback test transactions?

I have a Spring Boot application with Spring Data Rest and I use @WebIntegrationTest along with the TestRestTemplate in my integration tests. The base class for the tests looks something like…
10
votes
2 answers

In Spring Boot Test, how do I map a temporary folder to a configuration property?

I want to do a self-cleaning test In my situation, I have one of the components depend on a directory public class FileRepositoryManagerImpl implements .... @Value("${acme.fileRepository.basePath}") private File basePath; } The value is…
usr-local-ΕΨΗΕΛΩΝ
  • 26,101
  • 30
  • 154
  • 305
10
votes
3 answers

In Spring Boot, how to reset the metrics registry before each test?

I have tests and want to make assertions against micrometer metrics, but the tests run in random order so I want to reset or clear all the micrometer metrics before each test so my assertion are always correct.
lfmunoz
  • 822
  • 1
  • 9
  • 16
10
votes
1 answer

Replacement of @TransactionConfiguration

Currently, I am using below configuration my test classes- @TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = false) @Transactional As @TransactionConfiguration is deprecated, What can be the replacement for…
user1638734
  • 101
  • 1
  • 1
  • 4