简体   繁体   English

以 junit xml 格式保存测试用例

[英]save testscase in junit xml format

im trying to run from a tool some tests (python) and i want to save the results in junit xml format, it works fine if im doing it with the unittest.main() function like this:我试图从一个工具运行一些测试(python),我想将结果保存在 junit xml 格式,如果我用unittest.main() ZC1C425268E68385D1AB5074:F14A

if __name__ == "__main__":
with open('/path/to/unit_test_results.xml', 'wb') as output:
    unittest.main(
        testRunner=xmlrunner.XMLTestRunner(output=output),
        failfast=False, buffer=False, catchbreak=False)

But i want to do the same without the unittest.main() because i create my testsuite with a parameter like this:但是我想在没有unittest.main()的情况下做同样的事情,因为我使用这样的参数创建了我的测试套件:

def run_tests_TA(path):
suite = unittest.TestSuite()
suite.addTest(ParametrizedPath.parametrize(TestsTAs, path = path))
unittest.TextTestRunner(verbosity=2).run(suite)

If you have any ideas to help me i'd be very gratefull, thank you!如果您有任何想法可以帮助我,我将非常感激,谢谢!

I did it this way if someone needs:如果有人需要,我是这样做的:

test_cases = [TestCase('Test1', TestTAs.test_path(path))]
ts = [TestSuite("Results " + os.path.basename(path), test_cases)]

#print(TestSuite.to_xml_string(ts, prettyprint=True))
with open('output.xml', 'w') as f:
    TestSuite.to_file(f, ts)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM