반응형

 

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로 시작하지 않아 빠짐)

반응형

+ Recent posts