Skip to content

Instantly share code, notes, and snippets.

@KentaYamada
Created September 25, 2014 09:50
Show Gist options
  • Save KentaYamada/458829f77feeef23e7ac to your computer and use it in GitHub Desktop.
Save KentaYamada/458829f77feeef23e7ac to your computer and use it in GitHub Desktop.
Pythonで単体テスト
# -*- coding:utf-8 -*-
#テストしたい方を実装
def read_file():
with open('test.txt', mode='r') as f:
return f.read()
# -*- coding:utf-8 -*-
import unittest
from sample import read_file
#テストケースクラスを継承する
class SampleTest(unittest.TestCase):
#テスト用メソッド実装
def test_read_file(self):
self.assertEqual('test', read_file())
#テストケースクラスを継承したクラス全部テストしてくれるらしい
if __name__ == '__main__':
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment