单元测试 - Python unittest如何收集测试结果
PHP中文网
PHP中文网 2017-04-18 10:01:33
0
1
1010
PHP中文网
PHP中文网

认证高级PHP讲师

reply all (1)
Ty80

Just use the method of the unittest module itself:

import unittest class TestStringMethods(unittest.TestCase): def test_upper(self): self.assertEqual('foo'.upper(), 'F0O') self.assertEqual('foo'.upper(), 'F0O') def test_isupper(self): self.assertTrue('FOO'.isupper()) self.assertFalse('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) def main(): suite = unittest.TestLoader().loadTestsFromTestCase(TestStringMethods) test_result = unittest.TextTestRunner(verbosity=2).run(suite) print('All case number') print(test_result.testsRun) print('Failed case number') print(len(test_result.failures)) print('Failed case and reason') print(test_result.failures) for case, reason in test_result.failures: print case.id() print reason if __name__ == '__main__': main()
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!