{"id":152,"date":"2020-11-29T21:34:20","date_gmt":"2020-11-29T12:34:20","guid":{"rendered":"http:\/\/localhost:8000\/?p=152"},"modified":"2021-01-25T00:19:49","modified_gmt":"2021-01-24T15:19:49","slug":"python-unittest","status":"publish","type":"post","link":"http:\/\/localhost:8000\/2020\/11\/python-unittest.html","title":{"rendered":"\u6a19\u6e96\u30e2\u30b8\u30e5\u30fc\u30ebunittest\u3067python\u306e\u30c6\u30b9\u30c8\u3092\u66f8\u304f"},"content":{"rendered":"

Python\u3067\u672c\u683c\u7684\uff1f\u306b\u30c6\u30b9\u30c8\u3092\u66f8\u304d\u59cb\u3081\u307e\u3057\u305f\u3002\u6a19\u6e96\u30e9\u30a4\u30d6\u30e9\u30ea\u306e unittest<\/a> \u304c\u666e\u901a\u306b\u307e\u3042\u307e\u3042\u4f7f\u3044\u3084\u3059\u3044\u306e\u3067\u3001\u4f7f\u3044\u65b9\u3092\u307e\u3068\u3081\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n

\u57fa\u672c\u7684\u306a\u66f8\u304d\u65b9<\/h2>\n

\u57fa\u672c\u306f\u4ee5\u4e0b\u306e\u69cb\u9020\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n

import unittest\n\nclass TestSimple(unittest.TestCase):\n\n    @classmethod\n    def setUpClass(cls):\n        """\u5404\u30af\u30e9\u30b9\u304c\u5b9f\u884c\u3055\u308c\u308b\u76f4\u524d\u306b\u4e00\u5ea6\u3060\u3051\u547c\u3073\u51fa\u3055\u308c\u308b"""\n        print('setUpClass called.')\n\n    @classmethod\n    def tearDownClass(cls):\n        """\u5404\u30af\u30e9\u30b9\u304c\u5b9f\u884c\u3055\u308c\u305f\u76f4\u5f8c\u306b\u4e00\u5ea6\u3060\u3051\u547c\u3073\u51fa\u3055\u308c\u308b"""\n        print('tearDownClass called.')\n\n    def setUp(self):\n        """\u5404\u30c6\u30b9\u30c8\u30e1\u30bd\u30c3\u30c9\u304c\u5b9f\u884c\u3055\u308c\u308b\u76f4\u524d\u306b\u547c\u3073\u51fa\u3055\u308c\u308b"""\n        print('setUp called.')\n\n    def tearDown(self):\n        """\u5404\u30c6\u30b9\u30c8\u30e1\u30bd\u30c3\u30c9\u304c\u5b9f\u884c\u3055\u308c\u305f\u76f4\u5f8c\u306b\u547c\u3073\u51fa\u3055\u308c\u308b"""\n        print('tearDown called.')\n\n    def test_lower(self):\n        print(f'test_lower called. self_id: {id(self)}')\n        self.assertEqual('HOGE'.lower(), 'hoge')\n\n    def test_upper(self):\n        print(f'test_upper called. self_id: {id(self)}')\n        self.assertEqual('hoge'.upper(), 'HOGE')\n\n    @unittest.skip("this test method will be skipped")\n    def test_split(self):\n        print(f'test_split called. self_id: {id(self)}')\n        self.assertEqual(len('aa bb'.split()), 2)\n\nif __name__ == '__main__':\n    unittest.main()<\/code><\/pre>\n