반응형

 

setUp, tearDown

• test 마다 수행되는 초기화 및 정리 작업은 setUp(), tearDown()안에 넣으면 된다.

• 이 경우 매번 test_ 로 시작하는 함수가 불리기 전후로 setUp()과 tearDown()이 계속 불린다.

*


import unittest


class DestStringMethods(unittest.TestCase):

    def setUp(self):
        print 'setUp is called!!!'

    def tearDown(self):
        print 'tearDown is called!!!'

    def test_upper(self):
        self.assertEqual('foo'.upper(), 'FOO')

    def test_isupper(self):
        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()

 

• 제공되는 assertion. 그냥 assert 말고 다음거 써야한다.

 

반응형

+ Recent posts