unittest python,缺少功能测试

时间:2014-11-27 07:00:47

标签: python unit-testing python-2.7

我正在学习单元测试,我发现并非所有的测试功能都在运行。我发现前四个运行完美,但最后两个没有结果。如果我注释掉前四个函数,那么最后两个函数会出现。如何才能测试所有功能?

我是单位测试的新手,所以任何建议都很受欢迎

class MyTest(unittest.TestCase):
    def test_country(self):
        self.assertTrue(country in x)
    def test_company_size(self):
        self.assertTrue(company_size in x)
    def test_zipcode(self):
        self.assertTrue(zipcode in x)
    def test_region(self):
        self.assertTrue(region in x) 
    def test_street(self):
        self.assertTrue(street in x)  
    def test_address(self):
        self.assertTrue(address in x)  

if __name__ == '__main__':
    suite = unittest.TestLoader().loadTestsFromTestCase(MyTest)
    unittest.TextTestRunner(verbosity=3).run(suite)

结果:

test_company_size (__main__.MyTest) ... ok
test_country (__main__.MyTest) ... ok
test_region (__main__.MyTest) ... ok
test_zipcode (__main__.MyTest) ... ok

----------------------------------------------------------------------
Ran 4 tests in 0.000s

OK
[Finished in 1.5s]

0 个答案:

没有答案