KotlinTest with Spring Boot

KotlinTest with Spring Boot

2019年1月21日 「集まれKotlin好き!Kotlin愛好会 vol7」の談義資料です。

D1531f9547e24397c7e85881fac03096?s=128

Takehata Naoto

January 21, 2019
Tweet

Transcript

  1. 3.

       • Kotlin • Spring Boot • MyBatis

    • KotlinTest • Gradle • gRPC
  2. 4.

       • Kotlin • Spring Boot • MyBatis

    • KotlinTest • Gradle • gRPC
  3. 9.
  4. 11.
  5. 14.

    ( class SampleServiceForStringSpecTest : StringSpec() { init { val service

    = SampleService() "execute param 1 one " { service.execute(1) shouldBe "one" } •     • shouldBe KotlinTest 
  6. 17.

    ( class SampleServiceForBehaviorSpecTest : BehaviorSpec() { init { val service

    = SampleService() given("execute") { `when`("param1 ") { val result = service.execute(1) then("one ") { result.shouldBe("one") }
  7. 21.

    ( class SampleServiceForAnnotationSpecTest : AnnotationSpec() { val service = SampleService()

    @Test fun param1one() { service.execute(1) shouldBe "one" }
  8. 23.
  9. 28.
  10. 29.

       class SampleServiceTest: StringSpec() { init { forall(

    row(10, ""), row(100, "") ) { num, descrip8on -> "execute param ${descrip8on}   " { val service = SampleService() service.execute(num) shouldBe true } } } }
  11. 32.

     class SampleServiceForStringSpecTest : StringSpec() { init { val service

    = SampleService() "executeparam1one" { service.execute(1) shouldBe "one" } "f:executeparam2two" { service.execute(2) shouldBe "two" } } }    
  12. 34.

     class SampleServiceForStringSpecTest : StringSpec() { init { val service

    = SampleService() "executeparam1one" { service.execute(1) shouldBe "one" } "!executeparam2two" { service.execute(2) shouldBe "two" } } } !
  13. 38.
  14. 39.
  15. 40.

      @ContextConfiguration(classes = [TestApplicationContext::class]) class UserServiceImplTest( private val userService:

    UserService ): StringSpec() { init { ”getUserStatushogefuga" { //  } } }
  16. 44.

        package io.kotlintest.provided import io.kotlintest.AbstractProjectConfig import io.kotlintest.extensions.ProjectLevelExtension

    import io.kotlintest.spring.SpringAutowireConstructorExtension class ProjectConfig : AbstractProjectConfig() { override fun extensions(): List<ProjectLevelExtension> = listOf(SpringAutowireConstructorExtension) } • AbstractProjectConfig  • ConstructorInjection   
  17. 46.

        package io.kotlintest.provided import io.kotlintest.AbstractProjectConfig import io.kotlintest.extensions.ProjectLevelExtension

    import io.kotlintest.spring.SpringAutowireConstructorExtension class ProjectConfig : AbstractProjectConfig() { override fun extensions(): List<ProjectLevelExtension> = listOf(SpringAutowireConstructorExtension) } • io.kotlintest.provided   • ProjectConfig    •      
  18. 50.
  19. 51.
  20. 52.

    B B 8 2 8 2 / 8 2 9:2

    0 88 K S T 1 9 - 80 99 2-8 .8 9 2 / 2 0 2 8 2 9:2 0-88 2 1 8 2 / 8 2 / K 9/.K 1 9 - 80 /1 / 02 //: .8 / : : 8 2 / 9/.
  21. 53.
  22. 54.