Какова правильная аннотация, поскольку @SpringApplicationConfiguration и @WebIntegration устарели от Spring Boot Framework 1.4? Я пытаюсь играть с модульным тестированием.
Какая правильная аннотация, поскольку @SpringApplicationConfiguration, @WebIntegration, устарела в Spring Boot Framework?
Ответ 1
Взгляните на JavaDocs устаревших классов:
* @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 {
Есть ли также замена TestRestTemplate()?
Да, вот оно:
* @deprecated as of 1.4 in favor of
* {@link org.springframework.boot.test.web.client.TestRestTemplate}
*/
@Deprecated
public class TestRestTemplate extends RestTemplate {
Ответ 2
Хорошее место для начала теперь возможно: Тестирование улучшений в Spring Загрузка 1.4.
Они описывают базовый пример следующим образом:
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment=WebEnvironment.RANDOM_PORT)
public class MyTest {
}
в качестве замены, один из многих:
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(MyApp.class)
@WebIntegrationTest
public class MyTest {
}
Ответ 3
вы можете использовать @EnableAutoConfiguration или @SpringBootApplication.
для целей тестирования вы можете использовать @SpringBootTest (webEnvironment = 'ваше значение') или просто @SpringBootTest
просьба обращаться:
http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-testing.html
для тестирования REST, вы можете использовать @RestClientTest и настроить RestTemplateBuilder.
Ответ 4
Вы должны использовать эту аннотацию:
@ContextConfiguration(classes = main_class)