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

How to integration test auto configuration for a custom Spring Boot style starter library?

I am writing a library to provide some functionality that is shared between multiple different Spring Boot applications that I work with. I would like to do something similar to the auto-configuration that is provided by the many Spring Boot starter…
Joseph Downing
  • 1,099
  • 2
  • 12
  • 25
10
votes
2 answers

Hamcrest matcher comparing double value from JSON

I'm using the Hamcrest CoreMatcher classes as part of spring-test integration tests. My JSON looks like: {"data":[{"distanceInMiles":4,"id":"f97236ba-f4ef-4... And my integration test looks like: double miles = 4.0 Activity a = new…
Craig Otis
  • 31,257
  • 32
  • 136
  • 234
10
votes
4 answers

How can I use @IfProfileValue to test if a Profile is active?

So confusingly @IfProfileValue has nothing to do with @Profile or @ActiveProfiles. @Profile tests to see if a profile is active, @ActiveProfiles sets them as active, and @IfProfileValue allows you to check things in Spring Environment. Wut? I'd…
xenoterracide
  • 16,274
  • 24
  • 118
  • 243
10
votes
2 answers

How to view autoconfigure log output during spring boot tests (integration tests)

I am trying to debug a spring boot application during tests especially see the log output. I am not sure how to get the same autoconfigure log output during tests as the one I get when I run the application. I have tried this (from…
balteo
  • 23,602
  • 63
  • 219
  • 412
10
votes
1 answer

How to test ConfigurationProperties in Spring with JUnit?

I have a ConfigurationProperties class and want to test it using junit. But the object is always null. What might be missing in the following code? @EnableAutoConfiguration @ComponentScan @EnableConfigurationProperties(MyProperties.class) public…
membersound
  • 81,582
  • 193
  • 585
  • 1,120
10
votes
3 answers

Spring JUnit Test not loading full Application Context

Hi I am trying to so spring junit test cases... and I require my full application context to be loaded. However the junit test does not initialize the full application context. Test…
Shivam Sinha
  • 4,924
  • 7
  • 43
  • 65
10
votes
1 answer

@IfProfileValue vs @ActiveProfiles in the context of Spring test

I am in reference to Spring test and the following annotations: @IfProfileValue @ActiveProfiles I currently use @ActiveProfiles in my application and I recently discovered the existence of the @IfProfileValue annotation which seems to provide…
balteo
  • 23,602
  • 63
  • 219
  • 412
10
votes
5 answers

How to use spring's MockMultipartHttpServletRequest? Getting "no multipart boundary was found"

Clearly I'm not using this test fixture right. My servlet works just fine in tomcat, but when I try to use this mock, the multi-part boundary is not found. "the request was rejected because no multipart boundary was found". There is an answer here…
marathon
  • 7,881
  • 17
  • 74
  • 137
10
votes
4 answers

Service not been injected in Spring controller test with spring-test-mvc

I'm attempting to build a set of unit/integration tests for a Restful API Server I have created using Spring MVC 3.1.1. I'm trying to use the Spring-test-mvc. I'm relatively new to Spring and hence spring-test-mvc. I will include relevant sections…
Thomas Buckley
  • 5,836
  • 19
  • 62
  • 110
9
votes
3 answers

ERROR No qualifying bean of type 'org.springframework.security.oauth2.jwt.JwtDecoder' available

I am trying to write a test for my controller but the test environment fails to load with the given stackTrace. @PreAuthorize("hasAuthority('my.scope')") @GetMapping(value = "/path", produces = APPLICATION_JSON_VALUE) public…
Utsav10
  • 400
  • 2
  • 11
9
votes
2 answers

Integration testing using @SpringBootTest is not picking auto-configuration of library configured using spring.factories

We have a library ,in order to auto-configure the library we use spring.factories file under(src/main/resources/META-INF) which provides classes to auto-configure my library. Reference :…
Ayush Jain
  • 101
  • 2
  • 3
9
votes
1 answer

Cannot parse object because no supported Content-Type was not specified in response. Content-Type was 'text/html;charset=utf-8'

I'm trying to run the following Junit test: @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = { TestConfig.class, Account.class, AccountDao.class }, loader = AnnotationConfigContextLoader.class) public class AccountTest{ …
Jesse James
  • 1,203
  • 5
  • 22
  • 39
9
votes
3 answers

Spring MVC 5 ResultMatcher jsonPath null value

After upgrading my rest service from Spring Boot 1.5.10 to 2.0.0 I encountered my tests failing which passed before. Following Scenario: import org.mockito.internal.matchers.Null; import static…
mrkernelpanic
  • 4,268
  • 4
  • 28
  • 52
9
votes
2 answers

Use one spring boot context through all SpringBootTests

I want to be able to cache application context through different classes with tests using junit. Test classes are declared this way: @SpringBootTest @RunWith(SpringRunner.class) public class SomeIntegrationTest { } I saw this question Reuse spring…
Ruslan Akhundov
  • 2,178
  • 4
  • 20
  • 38
9
votes
2 answers

Spring dependency injection into Spring TestExecutionListeners not working

How can I use Spring dependency injection into a TestExecutionListener class I wrote extending AbstractTestExecutionListener? Spring DI does not seem to work with TestExecutionListener classes. Example of issue: The…
Dmitry K
  • 184
  • 2
  • 12