반응형
unittest
??파이선에서 지원하는 테스트 프레임웍
??기본 메뉴얼은 여기
??이건 좀 더 캐주얼
??다음 예제를 보자
import unittest
class DestStringMethods(unittest.TestCase):
def dest_upper(self):
self.assertEqual('foo'.upper(), 'FOO')
def test_isupper(self):
self.assertTrue('FOO'.isupper())
# self.assertTrue('Foo'.isupper())
def test_split(self):
s = 'hello world'
self.assertEqual(s.split(), ['hello', 'world'])
# check that s.split fails when the separator is not a string
with self.assertRaises(TypeError):
s.split(2)
if __name__ == '__main__':
unittest.main()
??위의 예제 돌리면은 DestStringMethods라는 클래스가 unittst.TestCase를 상속받았기 때문에 그 안의 method중에서 test로 시작하는 메소드들은 테스트의 대상이 된다. (맨위에 dest_upper는 test로 시작하지 않아 빠짐)
반응형
'Programming' 카테고리의 다른 글
| Python decorator class와 type 개념 정리 (0) | 2026.05.16 |
|---|---|
| 최소제곱법과 선형회귀 Cost Function 정리 (0) | 2026.05.16 |
| DQN Experience Replay 개념 정리 (0) | 2026.05.16 |
| Python metaclass와 decorator 동작 원리 정리 (0) | 2026.05.16 |
| DokuWiki 문법과 플러그인 기본 정리 (0) | 2026.05.16 |
