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
9
votes
1 answer

Spring ComponentScan excludeFilters annotation not working in Spring Boot Test context

I am using Spring Boot 1.4.3.RELEASE and want to exclude some components from being scanned when running the tests. @RunWith(SpringRunner.class) @SpringBootTest @ComponentScan( basePackages = {"com.foobar"}, excludeFilters = …
Javide
  • 2,477
  • 5
  • 45
  • 61
9
votes
1 answer

Context hierarchy in Spring Boot based tests

My Spring Boot application is started like this: new SpringApplicationBuilder() .sources(ParentCtxConfig.class) .child(ChildFirstCtxConfig.class) .sibling(ChildSecondCtxConfig.class) .run(args); Config classes are annotated with…
9
votes
1 answer

Spring RestController + Junit Testing

I'm playing around with spring-test of springframework. My intention is to test the following POST method in my rest controller: @RestController @RequestMapping("/project") public class ProjectController { @RequestMapping(method =…
Joschi
  • 2,118
  • 3
  • 16
  • 32
9
votes
2 answers

@TestPropertySource is not loading properties

I'm writing integration test for my spring boot application but when I try to override some properties using @TestPropertySource, it's loading the property file defined in the context xml but it's not overriding the properties defined in the…
kosker
  • 333
  • 1
  • 3
  • 12
9
votes
1 answer

TestExecutionListeners annotation prevents spring beans being wired in

Following the cassandra-unit with spring example I found the spring beans are not wired into the testclass resulting in nullpointer exceptions. I tried to minimise the problem and found it is probably not the Cassandra part, but instead the presence…
dr jerry
  • 9,768
  • 24
  • 79
  • 122
9
votes
2 answers

Specifying classes loading order in @ContextConfiguration in JUnit test cases

I am using junit 4.11 and spring-test-4.1.5 for writing integration test cases. I am using @ContextConfiguration annotation to load the configurations.like, @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes…
Anand Kadhi
  • 1,790
  • 4
  • 27
  • 40
9
votes
3 answers

Testing jsonpath that array contains specfic objects in any order

I'm testing a Spring controller which can give back a 400 with field errors. These field errors is an array of objects containing a "path" and "message" field. Now I want to test that some specific call returns multiple errors with specific path and…
Marcel Overdijk
  • 11,041
  • 17
  • 71
  • 110
9
votes
5 answers

Make a fake javax.sql.DataSource?

I have to write tests with String Test framework where many DB connections was used. In test I don't need all data sources but Spring want them all to inject. Are there any standard or well known fake javax.sql.DataSource implementation just to…
gavenkoa
  • 45,285
  • 19
  • 251
  • 303
9
votes
2 answers

testing spring-boot web-app with thymeleaf

I am trying to write tests to make sure that my controllers loads my views. When doing this i get an "circular view path exception". This is due to the thymeleaf-view-resolver not beeing present. A simple controller-method looks like…
Jørgen Skår Fischer
  • 883
  • 1
  • 10
  • 22
9
votes
5 answers

Failed to load ApplicationContext caused by ArrayIndexOutOfBoundsException in ClassReader

When I am running junit test class the below exception arises? How can i resolve this? Failed to load ApplicationContext java.lang.IllegalStateException: Failed to load ApplicationContext at…
deepak kumar
  • 229
  • 2
  • 3
  • 12
9
votes
2 answers

spring-data-jpa bean validation in junit tests

In my recent work I've used spring-data-jpa to take advantage of provided repositories. When it came to integration tests I am unable to configure (I assume) spring context for testing and as a outcome bean validation doesn't work in my tests. I am…
pejas
  • 273
  • 4
  • 9
9
votes
5 answers

spring testing: Another CacheManager with same name 'myCacheManager' already exists in the same VM

Before you mark this as duplicate please read the question first. I've read all the stuff about this exception however it does not solve the issue for me. And I do get a slightly different exception eg Another CacheManager with same name…
beginner_
  • 7,230
  • 18
  • 70
  • 127
9
votes
2 answers

What is the difference between @BeforeClass and Spring @TestExecutionListener beforeTestClass()

What is the difference between using JUnit @BeforeClass and the Spring @TestExecutionListener beforeTestClass(TestContext testContext) "hook"? If there is a difference, which one to use under which circumstances? Maven…
rallison
  • 199
  • 2
  • 3
  • 9
9
votes
2 answers

Unit testing REST Controller with spring-test-mvc

I have upgraded my Spring dependency to Spring 3.1.1.RELEASE and I'm trying to use spring-test-mvc to unit test a simple Controller. I have been following the technique used in Spring REST Controller Test with spring-test-mvc framework, since it…
CFL_Jeff
  • 2,589
  • 3
  • 31
  • 49
8
votes
2 answers

Spring @TestConfiguration affecting other test classes

I have several integration test classes, they all import configuration from a single @Configuration class, which is creating an externalApi mocked bean in a particular way (for illustration purposes, passing true as a constructor…
Pedro Estevão
  • 982
  • 1
  • 13
  • 41