Top "Spring-test" questions

`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.

How to set environment variable or system property in spring tests?

I'd like to write some tests that check the XML Spring configuration of a deployed WAR. Unfortunately some beans require …

java spring environment-variables spring-test
How to access Spring context in jUnit tests annotated with @RunWith and @ContextConfiguration?

I have following test class @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = {"/services-test-config.xml"}) public class MySericeTest { @Autowired MyService service; ... } Is …

spring junit spring-test applicationcontext
Rollback transaction after @Test

First of all, I've found a lot of threads on StackOverflow about this, but none of them really helped me, …

java spring hibernate junit spring-test
JUnit tests pass in Eclipse but fail in Maven Surefire

I have written some JUnit tests using JUnit 4 and spring-test libraries. When I run the tests inside Eclipse then run …

java spring maven-2 surefire spring-test
How to re-create database before each test in Spring?

My Spring-Boot-Mvc-Web application has the following database configuration in application.properties file: spring.datasource.url=jdbc:h2:tcp://localhost/~/pdk …

java spring spring-mvc spring-boot spring-test
Mockito Exception - when() requires an argument which has to be a method call on a mock

I have a very simple test case that is using Mockito and Spring Test framework. When I do when(pcUserService.…

java controller mockito spring-test
How to mock remote REST API in unit test with Spring?

Assume I have made a simple client in my application that uses a remote web service that is exposing a …

java unit-testing rest spring-test
How to unit test a Spring MVC controller using @PathVariable?

I have a simple annotated controller similar to this one: @Controller public class MyController { @RequestMapping("/{id}.html") public String doSomething(@…

java spring unit-testing spring-mvc spring-test
Spring Boot properties in 'application.yml' not loading from JUnit Test

What am I doing wrong? I'm using this little standalone App which runs and finds my src/main/resources/config/…

java spring junit spring-boot spring-test
Spring boot test configuration

I have a spring boot application with main class like below: @SpringBootApplication public class Application { public static void main(String[] …

java spring-boot spring-test