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
17
votes
3 answers

Testing Spring asyncResult() and jsonPath() together

I'm using a restful url to kick off a long-running backend process (it is normally on a cron schedule, but we want the ability to kick it off manually). The code below works and I see the result in the browser when I test…
Matt Byrne
  • 4,908
  • 3
  • 35
  • 52
16
votes
2 answers

Spring Testing with H2 db configuration

I use Oracle in production environment and I would like to use H2 for testing. I can type;
asyard
  • 1,743
  • 5
  • 21
  • 43
16
votes
3 answers

what's the difference between spring-boot-test vs spring-boot-starter-test?

I a project I am handling, I see these dependencies defined: org.springframework.boot spring-boot-test test
Phate
  • 6,066
  • 15
  • 73
  • 138
16
votes
3 answers

@MockBeans example use

I have a controller class that makes use of several services. I write a test for that controller like: @RunWith(SpringRunner.class) @WebMvcTest(value = PurchaseController.class, secure = false) public class PurchaseControllerTest { @MockBean …
mate00
  • 2,727
  • 5
  • 26
  • 34
16
votes
2 answers

How to test @Cacheable?

I am struggling with testing @Cacheable within a Spring Boot Integration Test. This is my second day learning how to do Integration Tests and all of the examples I have found use older versions. I also saw an example of assetEquals("some value",…
Grim
  • 2,398
  • 4
  • 35
  • 54
16
votes
1 answer

Spring TestRestTemplate vs RestTemplate

What is the difference between RestTemplate and its test version? When we do exception handling through @ControllerAdvice, RestTemplate is throwing the exception, but for same flow test version is returning json containing exception details. So, I…
krmanish007
  • 6,749
  • 16
  • 58
  • 100
15
votes
4 answers

'org.springframework.boot.web.server.LocalServerPort' is deprecated

Since Spring boot 2.7.1, @LocalServerPort (in the package org.springframework.boot.web.server.LocalServerPort) is deprecated. What can I use in stead of this annotation?
Rajat
  • 161
  • 1
  • 1
  • 5
15
votes
2 answers

Create instance of Spring´s ParameterizedTypeReference in Kotlin

I am trying to learn Kotlin, and test how it works with spring boot. My application is using a mongo database to store data and I have a Jersey resource for retrieving data. I am testing it using spring-boot-test and RestTestTemplate. The…
thomas77
  • 1,100
  • 13
  • 27
15
votes
3 answers

Getting java.net.HttpRetryException: cannot retry due to server authentication, in streaming mode

I've created a test for the creation of a new user: private static String USERS_ENDPOINT = "http://localhost:8080/users/"; private static String GROUPS_ENDPOINT = "http://localhost:8080/groups/"; @Test @DirtiesContext(classMode =…
Stefan Falk
  • 23,898
  • 50
  • 191
  • 378
15
votes
1 answer

JUnit tests fail when run together, but pass individually

I have a bunch of JUnit tests that all function individually. Each one is a true standalone unit test - single class under test. No contexts are required. I can run them all individually or all together either in Eclipse or via maven /…
Eric B.
  • 23,425
  • 50
  • 169
  • 316
15
votes
2 answers

Integration Testing Spring Boot With MockMVC

I'm having some trouble testing a Spring Boot application with MockMvc. I have the following test class: @RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(classes = {SpringConfiguration.class,…
David
  • 7,652
  • 21
  • 60
  • 98
15
votes
1 answer

No bean named 'org.springframework.context.annotation.ConfigurationClassPostProcessor.importRegistry' is defined

i am trying to run full package of junit test classes, and i have an audit classes for my domain classes as follows: @PrePersist public void prePersist(AuditableEntity e) { UserService userService =…
Mahmoud Saleh
  • 33,303
  • 119
  • 337
  • 498
15
votes
2 answers

Spring test injection not working when using TestExecutionListener

I want to use a custom TestExecutionListener in combination with SpringJUnit4ClassRunner to run a Liquibase schema setup on my test database. My TestExecutionListener works fine but when I use the annotation on my class the injection of the DAO…
nansen
  • 2,912
  • 1
  • 20
  • 33
15
votes
1 answer

Cannot JUnit test using Spring

My test is defined as follows: package com.mytest; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration public class SpringTestCase { @Test public void testSave_success() { fail("Not implemented"); } } My intention…
Lefteris Laskaridis
  • 2,292
  • 2
  • 24
  • 38
14
votes
1 answer

@IfProfileValue not working with JUnit 5 SpringExtension

I use junit5 with spring-starter-test, in order to run spring test I need to use @ExtendWith instead of @RunWith. However @IfProfileValue work with @RunWith(SpringRunner.class) but not with @ExtendWith(SpringExtension.class), below is my…
Chi Dov
  • 1,447
  • 1
  • 11
  • 22