栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何在python中自动将十几个测试用例添加到测试套件中

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何在python中自动将十几个测试用例添加到测试套件中

上面的模块很好,但是在尝试输入参数时,NoseTests可能很有趣,而且速度更快,可以很好地适合其他模块。

import os, unittestclass Tests():    def suite(self): #Function stores all the modules to be tested        modules_to_test = []        test_dir = os.listdir('.')        for test in test_dir: if test.startswith('test') and test.endswith('.py'):     modules_to_test.append(test.rstrip('.py'))        alltests = unittest.TestSuite()        for module in map(__import__, modules_to_test): module.testvars = ["variables you want to pass through"] alltests.addTest(unittest.findTestCases(module))        return alltestsif __name__ == '__main__':    MyTests = Tests()    unittest.main(defaultTest='MyTests.suite')

如果要将结果添加到日志文件中,请在末尾添加:

if __name__ == '__main__':    MyTests = Tests()    log_file = 'log_file.txt'    f = open(log_file, "w")     runner = unittest.TextTestRunner(f)    unittest.main(defaultTest='MyTests.suite', testRunner=runner)

同样,在模块的底部,您正在测试放置代码,如下所示:

class SomeTestSuite(unittest.TestSuite):    # Tests to be tested by test suite    def makeRemoveAudioSource():        suite = unittest.TestSuite()        suite.AddTest(TestSomething("TestSomeClass"))        return suite    def suite():        return unittest.makeSuite(TestSomething)if __name__ == '__main__':    unittest.main()


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/645401.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号