[英]Unittest test suite
我有一个测试套件,我执行了相同的操作,但是我的测试套件执行了一个测试脚本两次。 我只想执行一次测试脚本,并且应该为该报告生成报告。
Import HTMLTestRunner
class SmokeTestSuite(unittest.TestCase):
print('Running test suite')
dir = os.getcwd()
testLoad = unittest.TestLoader()
print(dir)
test_classes_to_run = [xyz_test_class]
suites_list = []
for test_class in test_classes_to_run:
suite = testLoad.loadTestsFromTestCase(test_class)
suites_list.append(suite)
print(suites_list)
newSuite = unittest.TestSuite(suites_list)
print(newSuite.countTestCases())
timestr = time.strftime("_%Y-%m-%d_%H.%M.%S")
resultFile = open(os.path.join(dir, "TestReport"+ timestr + ".html"), "w")
runner = HTMLTestRunner(stream=resultFile, title='Test Report', description='Tests Execution Report')
runner.run(newSuite)
它执行了一个测试脚本xyz_test_class两次。
TestCase是一个类,子代应定义测试方法,例如test_foo(self)
。 因此,将您的代码放入方法中,如下所示:
class SmokeTestSuite(TestCase):
def test_smoke(self):
'''your code goes here'''
无论如何,为什么不只使用自动发现的东西呢?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.