What is the proper annotation since @SpringApplicationConfiguration, @WebIntegration, is deprecated in Spring Boot Framework?

JavaSpring BootJunitSpring Annotations

Java Problem Overview


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.

Java Solutions


Solution 1 - Java

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 {

Solution 2 - Java

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 {
}

Solution 3 - Java

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.

Solution 4 - Java

You should use this annotation:

@ContextConfiguration(classes = main_class)

Solution 5 - Java

I have been using the following with no problem at all:

@ContextConfiguration(classes = Application.class)

Whereas Application is the name of my main class.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPersonView Question on Stackoverflow
Solution 1 - JavaArtem BilanView Answer on Stackoverflow
Solution 2 - Javauser1767316View Answer on Stackoverflow
Solution 3 - Javasatish chennupatiView Answer on Stackoverflow
Solution 4 - JavaGrigore ChisView Answer on Stackoverflow
Solution 5 - JavaKristijan FištrekView Answer on Stackoverflow