Spring Boot application test class

The following code snippet shows the generated SpringBootApplicationTest class, FirstWebServiceWithKotlinApplicationTests:

    @RunWith(SpringRunner::class)    @SpringBootTest    class FirstWebServiceWithKotlinApplicationTests {      @Test      fun contextLoads() {      }    }

The following are a few important things to note:

  • Package, import, and annotations are the same as that of a Java class.
  • :: is used to obtain a Kotlin class runtime reference. Compared to @RunWith(SpringRunner.class) in Java, the Kotlin code uses @RunWith(SpringRunner::class).
  • The declaration of the test class uses the Kotlin function syntax.

Get Mastering Spring 5.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.