Upgrade to Pro — share decks privately, control downloads, hide ads and more …

KotlinTest で始める Property-based Testing/kotlint...

KotlinTest で始める Property-based Testing/kotlintest-property-based-testing

Yusuke Hosonuma

August 24, 2019
Tweet

More Decks by Yusuke Hosonuma

Other Decks in Programming

Transcript

  1. Copyright (C) DeNA Co.,Ltd. All Rights Reserved. SoftWare Engineer in

    Test ςετࣗಈԽʢiOS / Android / Goʣ CI/CDɺςετٕज़ͷݚڀ
  2. Copyright (C) DeNA Co.,Ltd. All Rights Reserved. Agenda • KotlinTest

    ͬͯʁ • Property-based Testing ͬͯʁ • ͲΜͳͱ͖ʹ࢖͑Δʁ • ·ͱΊ ͳΜͱͳ͘ཧղ͕ΰʔϧ
  3. Copyright (C) DeNA Co.,Ltd. All Rights Reserved. Property-based Testing •

    ςετσʔλΛϥϯμϜʹੜ੒ͤ͞ • ؔ਺͕ຬͨ͢ੑ࣭ʢPropertyʣΛݕূ͢Δ
  4. Copyright (C) DeNA Co.,Ltd. All Rights Reserved. Property-based Testing •

    ςετσʔλΛϥϯμϜʹੜ੒ͤ͞ • ͦͷؔ਺͕ຬͨ͢ੑ࣭ʢPropertyʣΛݕূ͢Δ ͳΔ΄ͲɺΘ͔ΒΜɻ ྫΛݟͯΈΔ
  5. Copyright (C) DeNA Co.,Ltd. All Rights Reserved. 1 + 1

    = 2 / 2 + 3 = 5 class AddSpec: StringSpec({ "add" { forall( row(1, 1, 2), row(2, 3, 5) ) { a, b, expected -> (a + b) shouldBe expected } } })
  6. Copyright (C) DeNA Co.,Ltd. All Rights Reserved. class AddSpec: StringSpec({

    "add" { forall( row(1, 1, 2), row(2, 3, 5) ) { a, b, expected -> (a + b) shouldBe expected } } }) ೖྗ஋ͱظ଴஋Λ༻ҙͯ͠ 1 + 1 = 2 / 2 + 3 = 5
  7. Copyright (C) DeNA Co.,Ltd. All Rights Reserved. class AddSpec: StringSpec({

    "add" { forall( row(1, 1, 2), row(2, 3, 5) ) { a, b, expected -> (a + b) shouldBe expected } } }) ݁Ռͱظ଴஋͕Ұக͢Δ͔ʁ 1 + 1 = 2 / 2 + 3 = 5
  8. Copyright (C) DeNA Co.,Ltd. All Rights Reserved. KotlinTestͰݕূ class AddProperty:

    StringSpec({ "commutative" { assertAll { a: Int, b: Int -> (a + b) shouldBe (b + a) } } })
  9. Copyright (C) DeNA Co.,Ltd. All Rights Reserved. KotlinTestͰݕূ class AddProperty:

    StringSpec({ “commutative" { assertAll { a: Int, b: Int -> (a + b) shouldBe (b + a) } } }) ͢΂ͯͷ
  10. Copyright (C) DeNA Co.,Ltd. All Rights Reserved. KotlinTestͰݕূ class AddProperty:

    StringSpec({ “commutative" { assertAll { a: Int, b: Int -> (a + b) shouldBe (b + a) } } }) औΓ͏Δ஋BͱCʹ͍ͭͯ
  11. Copyright (C) DeNA Co.,Ltd. All Rights Reserved. KotlinTestͰݕূ class AddProperty:

    StringSpec({ "commutative" { assertAll { a: Int, b: Int -> (a + b) shouldBe (b + a) } } }) B CC BͰ͋Δ͜ͱ
  12. Copyright (C) DeNA Co.,Ltd. All Rights Reserved. KotlinTestͰݕূ class AddProperty:

    StringSpec({ "commutative" { assertAll { a: Int, b: Int -> (a + b) shouldBe (b + a) } } }) B CC BͰ͋Δ͜ͱ ϥϯμϜͳೖྗ஋ʹରͯ͠ ຬͨ͞ΕΔ΂͖ੑ࣭Λݕূ ৗʹ
  13. Copyright (C) DeNA Co.,Ltd. All Rights Reserved. debug print ͯ͠ΈΔͱ

    ཚ਺Ͱ ճࢼߦ͞ΕͯΔ ύε͠ͳ͍σʔλ͕ͳ͍͔ େྔͷཚ਺Ͱ͋ͿΓग़͢ ͱߟ͑Δͱ෼͔Γ΍͍͢
  14. Copyright (C) DeNA Co.,Ltd. All Rights Reserved. ໎࿏ੜ੒ • ͲΜͳ໎࿏Ͱ΋ղ͚ͳ͍ͱ੒ཱ͠ͳ͍

    • ٯʹݴ͑͹ղ͚ͳ͍ͱόά • ʮඞͣղ͚Δʯͱ͍͏ੑ࣭Λݕূ͢Δ ྫ͑͹ Monkey Runner ΋ ϥϯμϜͳΠϕϯτΛൃߦ͠ଓ͚ ʮམͪͳ͍ʯੑ࣭Λݕূ͢Δ "OESPJEͷ
  15. Copyright (C) DeNA Co.,Ltd. All Rights Reserved. Τϯίʔυ / σίʔυ

    • ͲΜͳ஋ΛΤϯίʔυ → σίʔυ ͯ͠΋ • ඞͣʮݩͷ஋ʹ໭Δʯͱ͍͏ੑ࣭Λݕূ
  16. Copyright (C) DeNA Co.,Ltd. All Rights Reserved. ߴ଎ vs ௿଎

    • ߴ଎ͳίʔυ͸଎͍ʢ͚Ͳෳࡶʣ • ௿଎ͳίʔυ͸໌നʢ͚Ͳ஗͍ʣ • ͲͪΒ΋ʮಉ݁͡ՌʹͳΔʯͱ͍͏ੑ࣭Λར༻ • લऀͷݕূʹޙऀΛར༻͢Δ
  17. Copyright (C) DeNA Co.,Ltd. All Rights Reserved. ·ͱΊ • KotlinTest

    ͸ ςεςΟϯάϑϨʔϜϫʔΫ • Property-based Testing ΋αϙʔτ • ϥϯμϜͳೖྗΛݩʹੑ࣭Λݕূ • Example-based Λஔ͖׵͑Δ΋ͷͰ͸ͳ͍
  18. Copyright (C) DeNA Co.,Ltd. All Rights Reserved. ·ͱΊ • KotlinTest

    ͸ DSL Λ׆༻ͨ͠ςετϥΠϒϥϦ • Property-based Testing ΋αϙʔτ • ϥϯμϜͳೖྗΛݩʹੑ࣭Λݕূ • Example-based Λஔ͖׵͑Δ΋ͷͰ͸ͳ͍ ͱ͖ͬͭͮΒ͍ߟ͑ํ͕ͩ ͓֮͑ͯ͘ͱڧྗͳΧʔυ ࠷ॳ͸