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.   

  2.  :  Twi%er:@n_takehata %)& +,#,!Kotlin +', $*,( +*"11 

    +
  3.    • Kotlin • Spring Boot • MyBatis

    • KotlinTest • Gradle • gRPC
  4.    • Kotlin • Spring Boot • MyBatis

    • KotlinTest • Gradle • gRPC
  5.      

  6.  1 1 2 B 1 1 . 1 4

    3
  7.  1 1 2 B 1 1 . 1 4

    3
  8.     

  9.   • / • : • K : //

    . / / / ./ / / ./
  10.   testCompile('io.kotlintest:kotlintest-runner-junit5:3.1.7')

  11.  

  12.   •    •   

    •    
  13.  

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

    = SampleService() "execute param 1 one " { service.execute(1) shouldBe "one" } •     • shouldBe KotlinTest 
  15.  • FB • ) F FB • ( S

  16.    

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

    = SampleService() given("execute") { `when`("param1 ") { val result = service.execute(1) then("one ") { result.shouldBe("one") }
  18.  • D • ( e B • 3 K

    )( `
  19. ) ((   

  20.    

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

    @Test fun param1one() { service.execute(1) shouldBe "one" }
  22.  • KT @ U • J

  23.  

  24.   • ( ) • K1 • K0

  25.  1 1 2 B 1 1 . 1 4

    3
  26.     

  27.  •   •   

  28. 

  29.    class SampleServiceTest: StringSpec() { init { forall(

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

  31.   

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

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

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

    = SampleService() "executeparam1one" { service.execute(1) shouldBe "one" } "!executeparam2two" { service.execute(2) shouldBe "two" } } } !
  35. ) (( 2    

  36.     • B • •

  37.  1 1 2 B 1 1 . 1 4

    3
  38. None
  39.  

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

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

  42.   

  43.   testCompile("io.kotlintest:kotlintest-extensions-spring:3.1.8")     

  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   
  45. 

  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    •      
  47.       

  48.     

  49.  1 1 2 B 1 1 . 1 4

    3
  50.  

  51. •    # $)" • (%*  

      •   &+'!
  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/.
  53.  

  54. 

  55. 201924     Java→Kotlin  https://gihyo.jp/magazine/SD/archive/2019/201902