代码之家  ›  专栏  ›  技术社区  ›  Jonathan

如何以编程方式运行python unittest测试

  •  1
  • Jonathan  · 技术社区  · 8 年前

    我有以下测试 the unittest documentation

    import unittest
    
    class TestStringMethods(unittest.TestCase):
    
        def test_upper(self):
            self.assertEqual('foo'.upper(), 'FOO')
    
        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)
    
    if __name__ == '__main__':
        unittest.main()
    

    如何从另一个Python程序运行上述测试,并能够检查结果以及哪些测试失败(如果有的话)?

    0 回复  |  直到 5 年前