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

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

70d9714ea13fc1133803d61fb16e4160?s=128

Yusuke Hosonuma

August 24, 2019
Tweet

Transcript

  1. 3.

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

    Test ςετࣗಈԽʢiOS / Android / Goʣ CI/CDɺςετٕज़ͷݚڀ
  2. 5.

    Copyright (C) DeNA Co.,Ltd. All Rights Reserved. Agenda • KotlinTest

    ͬͯʁ • Property-based Testing ͬͯʁ • ͲΜͳͱ͖ʹ࢖͑Δʁ • ·ͱΊ ͳΜͱͳ͘ཧղ͕ΰʔϧ
  3. 14.

    Copyright (C) DeNA Co.,Ltd. All Rights Reserved. Property-based Testing •

    ςετσʔλΛϥϯμϜʹੜ੒ͤ͞ • ؔ਺͕ຬͨ͢ੑ࣭ʢPropertyʣΛݕূ͢Δ
  4. 15.

    Copyright (C) DeNA Co.,Ltd. All Rights Reserved. Property-based Testing •

    ςετσʔλΛϥϯμϜʹੜ੒ͤ͞ • ͦͷؔ਺͕ຬͨ͢ੑ࣭ʢPropertyʣΛݕূ͢Δ ͳΔ΄ͲɺΘ͔ΒΜɻ ྫΛݟͯΈΔ
  5. 18.

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

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

    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. 23.
  9. 24.

    Copyright (C) DeNA Co.,Ltd. All Rights Reserved. KotlinTestͰݕূ class AddProperty:

    StringSpec({ "commutative" { assertAll { a: Int, b: Int -> (a + b) shouldBe (b + a) } } })
  10. 25.

    Copyright (C) DeNA Co.,Ltd. All Rights Reserved. KotlinTestͰݕূ class AddProperty:

    StringSpec({ “commutative" { assertAll { a: Int, b: Int -> (a + b) shouldBe (b + a) } } }) ͢΂ͯͷ
  11. 26.

    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ʹ͍ͭͯ
  12. 27.

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

    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Ͱ͋Δ͜ͱ ϥϯμϜͳೖྗ஋ʹରͯ͠ ຬͨ͞ΕΔ΂͖ੑ࣭Λݕূ ৗʹ
  14. 30.

    Copyright (C) DeNA Co.,Ltd. All Rights Reserved. debug print ͯ͠ΈΔͱ

    ཚ਺Ͱ ճࢼߦ͞ΕͯΔ ύε͠ͳ͍σʔλ͕ͳ͍͔ େྔͷཚ਺Ͱ͋ͿΓग़͢ ͱߟ͑Δͱ෼͔Γ΍͍͢
  15. 35.

    Copyright (C) DeNA Co.,Ltd. All Rights Reserved. ໎࿏ੜ੒ • ͲΜͳ໎࿏Ͱ΋ղ͚ͳ͍ͱ੒ཱ͠ͳ͍

    • ٯʹݴ͑͹ղ͚ͳ͍ͱόά • ʮඞͣղ͚Δʯͱ͍͏ੑ࣭Λݕূ͢Δ ྫ͑͹ Monkey Runner ΋ ϥϯμϜͳΠϕϯτΛൃߦ͠ଓ͚ ʮམͪͳ͍ʯੑ࣭Λݕূ͢Δ "OESPJEͷ
  16. 37.

    Copyright (C) DeNA Co.,Ltd. All Rights Reserved. Τϯίʔυ / σίʔυ

    • ͲΜͳ஋ΛΤϯίʔυ → σίʔυ ͯ͠΋ • ඞͣʮݩͷ஋ʹ໭Δʯͱ͍͏ੑ࣭Λݕূ
  17. 39.

    Copyright (C) DeNA Co.,Ltd. All Rights Reserved. ߴ଎ vs ௿଎

    • ߴ଎ͳίʔυ͸଎͍ʢ͚Ͳෳࡶʣ • ௿଎ͳίʔυ͸໌നʢ͚Ͳ஗͍ʣ • ͲͪΒ΋ʮಉ݁͡ՌʹͳΔʯͱ͍͏ੑ࣭Λར༻ • લऀͷݕূʹޙऀΛར༻͢Δ
  18. 41.

    Copyright (C) DeNA Co.,Ltd. All Rights Reserved. ·ͱΊ • KotlinTest

    ͸ ςεςΟϯάϑϨʔϜϫʔΫ • Property-based Testing ΋αϙʔτ • ϥϯμϜͳೖྗΛݩʹੑ࣭Λݕূ • Example-based Λஔ͖׵͑Δ΋ͷͰ͸ͳ͍
  19. 42.

    Copyright (C) DeNA Co.,Ltd. All Rights Reserved. ·ͱΊ • KotlinTest

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