What is the proper annotation since @SpringApplicationConfiguration
and @WebIntegration
are deprecated as of Spring Boot Framework 1.4? I'm trying to play around with unit testing.
-
4@SpringBootTest(webEnvironment=WebEnvironment.MOCK) – Ulises Sep 09 '16 at 18:18
-
Take a look at https://spring.io/blog/2016/04/15/testing-improvements-in-spring-boot-1-4 – Ilya Serbis Jan 26 '17 at 12:49
-
It is not an answer to you question but, Spring boot is not a framework. But it is an opinionated view of Spring Framework. https://springhow.com/spring-boot-and-spring/ – Raja Anbazhagan Aug 09 '20 at 19:42
5 Answers
Take a look into JavaDocs of deprecated classes:
* @deprecated as of 1.4 in favor of
* {@link org.springframework.boot.test.context.SpringBootTest} with
* {@code webEnvironment=RANDOM_PORT} or {@code webEnvironment=DEFINED_PORT}.
*/
...
@Deprecated
public @interface WebIntegrationTest {
* @deprecated as of 1.4 in favor of {@link SpringBootTest} or direct use of
* {@link SpringBootContextLoader}.
*/
...
@Deprecated
public @interface SpringApplicationConfiguration {
Is there also a replacement for TestRestTemplate()?
Yes, here it is:
* @deprecated as of 1.4 in favor of
* {@link org.springframework.boot.test.web.client.TestRestTemplate}
*/
@Deprecated
public class TestRestTemplate extends RestTemplate {

- 113,505
- 11
- 91
- 118
A good place to start is now probably: Testing improvements in Spring Boot 1.4.
They describe a basic sample like the following:
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment=WebEnvironment.RANDOM_PORT)
public class MyTest {
}
as a replacement to, one of many:
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(MyApp.class)
@WebIntegrationTest
public class MyTest {
}

- 17,291
- 7
- 48
- 81

- 3,276
- 3
- 37
- 46
-
2how does the upper version of you know that the ApplicationConfiguration is in the class MyApp.class ? when I implement it your way it fails to load the applicationContext – Nali Aug 04 '17 at 07:19
-
Good question, I do not know but it might be only one runing App at a time. – user1767316 Aug 22 '17 at 09:38
you can use @EnableAutoConfiguration or @SpringBootApplication.
for testing purpose you can use @SpringBootTest(webEnvironment='your value') or simply @SpringBootTest
please refer :
http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-testing.html
for testing the REST, you can use @RestClientTest and configure a RestTemplateBuilder.

- 2,602
- 1
- 18
- 27
You should use this annotation:
@ContextConfiguration(classes = main_class)

- 36,322
- 27
- 84
- 93

- 79
- 1
- 2
-
This doesn't work as during integration test my app is unable to get the database URL params from the properties file. – Neeraj Jain Nov 19 '17 at 20:38
-
1@NeerajJain to be able to get them just a small tweak is necessary: @ContextConfiguration(classes = main_class, initializers = ConfigFileApplicationContextInitializer.class) – sowieso-fruehling Mar 12 '19 at 17:03
I have been using the following with no problem at all:
@ContextConfiguration(classes = Application.class)
Whereas Application is the name of my main class.

- 21
- 3