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

テストで100点取る方法 / How to get all passed tests

テストで100点取る方法 / How to get all passed tests

初心者向けに単体テストとはどういうものかを簡単に説明したスライド

Pudding

April 25, 2018
Tweet

More Decks by Pudding

Other Decks in Programming

Transcript

  1. ؔ਺" def A(number: int) -> bool: if number > 0:

    return True if number < 0: return False ਺ࣈͷਖ਼ෛΛ൑ఆ͢Δؔ਺ ༩͑ΒΕͨ਺ࣈ͕ਖ਼ͳΒ5SVFɼෛͳΒ'BMTFΛฦ͢ ੍໿ɿOVNCFS
  2. def A(number: int) -> bool: if number > 0: return

    True if number < 0: return False OVNCFSͷͱ͖ɼԿ΋஋ΛSFUVSO͠ͳ͍ ʢ/POFʢ/VMMΈ͍ͨͳͷʣ͕ฦΔʣ όάͷݩ
  3. VOJUUFTUΛॻ͍ͯΈΔ import unittest class ATestCase(unittest.TestCase): def test_positive(self): numbers = [1,

    20, 300] for number in numbers: self.assertTrue(A(number)) def test_negative(self): numbers = [-1, -20, -300] for number in numbers: self.assertFalse(A(number)) def test_zero(self): self.assertTrue(A(0)) 5SVF͕ฦΔ͸ͣ 'BMTF͕ฦΔ͸ͣ ʁʁʁʁʁ
  4. ςετΛ࣮ߦͯ͠ΈΔ FAIL: test_zero (hoge.ATestCase) --------------------------------------------------- Traceback (most recent call last):

    File "/path/to/hoge.py", line 21, in test_zero self.assertTrue(A(0)) AssertionError: None is not true --------------------------------------------------- Ran 3 tests in 0.001s FAILED (failures=1) ݁Ռ͕A5SVFA
 ͡Όͳ͍Αʂ ˔ ςετʹࣦഊ͢Δ
 ࣗ෼͕༧ظͨ͠΋ͷͱҧ͏݁Ռ͕ฦ͖ͬͯͨ ˔ ςετέʔεΛਖ਼͘͠ઃఆ͢Δ͜ͱ͕ॏཁ
  5. ςετͰຬ఺औΔํ๏ import unittest class ATestCase(unittest.TestCase): def test_positive(self): self.assertTrue(True) def test_negative(self):

    self.assertTrue(True) def test_zero(self): self.assertTrue(True) શͯͷςετʹ͍ͭͯ5SVFͰ௨͢