通过 Web 界面执行 python 单元测试 [英] Perfom python unit tests via a web interface
问题描述
是否可以通过 Web 界面执行单元测试测试...如果可以,如何进行?
编辑:现在我想要结果......对于测试,我希望它们是自动化的......可能每次我对代码进行更改时.对不起,我忘了说得更清楚
此时此答案已过时:
- 使用
(来源:
(来源:
(来源:
(来源:snowpeaksoftware.com)Is it possible to perform unittest tests via a web interface...and if so how?
EDIT: For now I want the results...for the tests I want them to be automated...possibly every time I make a change to the code. Sorry I forgot to make this more clear
解决方案EDIT:
This answer is outdated at this point:
- Use Jenkins instead of Hudson (same thing, new name).
- Use django-jenkins instead of xmlrunner.py.
The link to django-jenkins goes to a nice tutorial on how to use Jenkins with Django. I'll leave the text below since it still has some nice information.
As Bryan said, I'd use Hudson to schedule, run, and collect the test results. You can modify your tests to use xmlrunner.py (written by Sebastian Rittau), which will output your test results into an JUnit compatible XML file for Hudson.
Here's an example of how the test code would use xmlrunner:
import unittest import xmlrunner class TheTest(unittest.TestCase): def testOne(self): self.assertEquals(1, 1) def testTwo(self): self.assertEquals(2, 2) def testThree(self): self.assertEquals(3, 4) if __name__ == '__main__': suite = unittest.TestLoader().loadTestsFromTestCase(TheTest) xmlrunner.XMLTestRunner().run(suite)
Once you install Hudson, you'll create a new project for the source repository you're testing. You'll need to RTFM, but in a nutshell:
- Under Source Code Management, you'll enter your repositories information and make it poll the repo periodically (I usually just do * * * * * so it checks every minute)
- Add a command that actually runs the test script (like
python test.py
). - Check the Publish JUnit test result report. If it has an error like
'TEST-*.xml' doesn't match anything
you can safely ignore it. It'll look something like this:
(source: snowpeaksoftware.com)
Once that's all done you'll be able to see test results for every time Hudson runs after check-in. It'll look something like this:
(source: snowpeaksoftware.com)You also get more detailed pages like this page:
(source: snowpeaksoftware.com)and this page:
(source: snowpeaksoftware.com)这篇关于通过 Web 界面执行 python 单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!