Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which version of spring boot has @WebIntegrationTest included, it shows red in Intellij at the time of adding it

I have Spring Boot test dependency added in Gradle file as

testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test'
ext['mockito.version'] = '2.7.5'

Still not able to use @WebIntegrationTest, it shows red color if I try to add in Intellij. What should I have in my application so that I would be able to test REST API with @WebIntegrationTest?

I'm able to test it with different method but just not able to get why it is failing

like image 627
tyro Avatar asked Jun 15 '17 12:06

tyro


2 Answers

Still not able to use @WebIntegrationTest, it shows red color if I try to add in intellij.

As said by you that you have springboot 1.5.1 version, WebIntegrationTest class was deprecated from 1.4 in favor of SpringBootTest.

Below is the javadocs supporting above.

  • @since 1.2.1 * @see IntegrationTest * @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}. */ @Documented @Inherited @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) @BootstrapWith(WebAppIntegrationTestContextBootstrapper.class) @Deprecated public @interface WebIntegrationTest {

You have two choices here,

  1. Ditch WebIntegrationTest class and start using SpringBootTest
  2. Downgrade springboot version lower to 1.4.0 and use WebIntegrationTest(not recommended)

Here is the link of 1.4.0-M2 release notes explaining about the deprecation of WebIntegrationTest

Hope this helps!

like image 83
harshavmb Avatar answered Sep 30 '22 13:09

harshavmb


These deprecated annotations

@SpringApplicationConfiguration(classes = arrayOf(BootApplication::class))
@WebIntegrationTest("server.port=8081")

in Spring Boot 1.5+ are equivalent to

@SpringBootTest(classes = arrayOf(BootApplication::class), properties = arrayOf("server.port=8081"))
@WebAppConfiguration
like image 20
naXa Avatar answered Sep 30 '22 14:09

naXa