如何多次运行我的Django测试用例?

时间:2012-03-28 22:32:42

标签: django unit-testing django-testing django-unittest

我想对我的一个测试用例进行一些详尽的测试(例如,创建一个文档,调试我遇到的一些奇怪的事情......)

我的野蛮力量是使用python manage.py test myappPopenos.system循环中发射def SimpleTest(unittest.TestCase): def setUp(self): def test_01(self): def tearDown(self): def suite(): suite = unittest.TestCase() suite.add(SimpleTest("setUp")) suite.add(SimpleTest("test_01")) suite.add(SimpleTest("tearDown")) return suite def main(): for i in range(n): suite().run("runTest") ,但现在我又恢复了原状?.....

python manage.py test myapp

我跑了 File "/var/lib/system-webclient/webclient/apps/myapps/tests.py", line 46, in suite suite = unittest.TestCase() File "/usr/lib/python2.6/unittest.py", line 216, in __init__ (self.__class__, methodName) ValueError: no such test method in <class 'unittest.TestCase'>: runTest 我得到了

unittest.TestCase

我已经用Google搜索了错误,但我仍然无能为力(我被告知要添加一个空的runTest方法,但这听起来不对......)

嗯,根据python的SimpleTest

  

最简单的TestCase子类将简单地覆盖runTest()   方法以执行特定的测试代码

如您所见,我的整个目标是运行{{1}}次N次。我需要跟踪传球,对N的失败。

我有什么选择?

感谢。

1 个答案:

答案 0 :(得分:0)

通过单元测试跟踪比赛条件非常棘手。有时你最好使用像Selenium这样的自动化测试工具来打你的前端 - 与单元测试不同,环境是相同的,并且不需要额外的工作来确保并发性。当没有更好的选择时,这是在测试中运行并发代码的一种方法:http://www.caktusgroup.com/blog/2009/05/26/testing-django-views-for-concurrency-issues/

请记住,并发测试并不能证明你没有竞争条件 - 不能保证它会在进程间重新创建所有可能的执行顺序组合。

相关问题