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

1 test 1 assert ?

B765faf519f19520e1495bd870f4d7f0?s=47 PoohSunny
September 30, 2017

1 test 1 assert ?

TDDBC Tokyo 2017-09 でのLTスライドです。 https://tddbc.connpass.com/event/65484/

B765faf519f19520e1495bd870f4d7f0?s=128

PoohSunny

September 30, 2017
Tweet

Transcript

  1. 1 test 1 assert ? 1

  2. ߴڮ ཅଠ࿠(@PoohSunny) { role: "Engineer team leader", lang: ["Java", "Groovy",

    "Swift"] } 2
  3. 3

  4. ϖΞϓϩσϞ 4

  5. 1 test 1 assertion 5

  6. xUTPͱͷग़ձ͍ 6

  7. ਺೥ޙ3 3 photo: https://www.flickr.com/photos/daverusso88/20860542330/in/photolist- xMnJsW-8H8jnW-8BDdLz-fS9XhN-e3qtWG-oaibHC-eRMCCx-q9Ftni-n7Lmvm-supyFV-gXyxGZ- fEKqSK-sqqxce-sfR8k1-q7N9Ta-dDw4Zq-9ML2MP-oa6sWm-J5F4zN-4vX6LP-nW3r1Q- rF4QJJ-8BWJj9-A1MjG7-sqqpKR-HgcdWN-7Dy6QC-s7M3Dn-w2RjN3-TZXibu-mMD2tR-o9TZi6- shS8mE-hWRzr-WJPkXw-xe6Rnv-DWz4Ra-yGju6j-fkfg3o-ghz6JD-wR4HYP-7xhvzK-rN2UEW- krfJu3-Duju1z-FSwQ8h-8yNSK2-4vXc2a-DaLuo5-zZyYuS 7

  8. xUTPͱͷग़ձ͍(෺ཧ)4 4 ಈը: https://engineers.sg/video/unit-test-craftsmanship-agile-singapore- conference-2016--1168 εϥΠυ: http://singapore2016.xunitpatterns.com/ 8

  9. γϯάϧΞαʔγϣϯ9 • ࿑ಇ࣌ؒܭࢉͷςετ // then assertEquals(720, result.getWorkTime()); • ٳܜ࣌ؒܭࢉͷςετ //

    then List<Integer> breakTimeList = result.getBreakTimeList(); assertEquals(2, breakTimeList.size()); assertEquals(60, breakTimeList[0]); assertEquals(45, breakTimeList[1]); 9 http://xunitpatterns.com/Principles%20of%20Test%20Automation.html#Single Condition Test 9
  10. 1 test 1 assertϗ ϯτʁ 10

  11. ·ͱΊ͓͍ͯͨํ͕ Θ͔Γ΍ͦ͢͏ // then List<Integer> breakTimeList = result.getBreakTimeList(); assertEquals(2, breakTimeList.size());

    assertEquals(60, breakTimeList[0]); assertEquals(45, breakTimeList[1]); 11
  12. ಡΈ΍͍͢ܗʹ ϦϑΝΫλϦϯά • ྫ͑͹JUnit5 + AssertJΛར༻ // then List<Integer> breakTimeList

    = result.getBreakTimeList(); assertThat(breakTimeList).hasSize(2).containsExactly(60, 45); 12
  13. ΧελϜΞαʔγϣϯ10 • ϔϧύʔΛ࡞੒͠ɺΞαʔγϣϯͷ࣮ॲཧ͸ͦ ͪΒʹҠಈ 10 http://xunitpatterns.com/Custom%20Assertion.html 13

  14. ϝιου೔ຊޠԽ΋ख // then List<Integer> breakTimeList = result.getBreakTimeList(); ٳܜ͸2ճ෼ܭࢉ͞Εͯ(breakTimeList, _1ͭ໨ͷܭࢉ࣌ؒ͸(60), _2ͭ໨ͷܭࢉ࣌ؒ͸(45));

    14
  15. ϝϯςφϯεੑ͕٘ਜ਼ʹͳ Δʁ • ςετͷڞ௨ԽͬͯͲΕ΄Ͳॏཁʁ • ͜ΕʹΑͬͯͲͷ͘Β͍ಡΈ΍͕͢͞૿͢ʁ 15

  16. ಡΈ΍͘͢ͳΒͳ͍Α͏ͳΒ ΋͠ಡΈ΍͘͢ͳΒͳ͍ͳΒɺγϯάϧΞαʔγ ϣϯਥʹͳΔͭ΋Γ͸ͳ͍Α — Principle: Verify One Condition per Test

    11 11 http://xunitpatterns.com/Principles%20of%20Test%20Automation.html#Single Condition Test ΑΓҙ༁ 16
  17. Single Assertion ͸ૉ੖Β͍͠ 17

  18. Ͱ΋όϥϯε͸͋Δ Αʂ 18

  19. ͓͠·͍ 19