带有测试套件和测试用例的 TestSuite
我需要制作一个大的 python 套件,其中包含我已经制作好的其他手提箱和测试用例,可以一起执行。
我该怎么做?
例如,这里有一个我要添加的套件(suiteFilter.py):
import testFilter1
import testFilter2
import unittest
import sys
def suite():
return unittest.TestSuite((\
unittest.makeSuite(testFilter1.TestFilter1),
unittest.makeSuite(testFilter2.TestFilter2),
))
if __name__ == "__main__":
result = unittest.TextTestRunner(verbosity=2).run(suite())
sys.exit(not result.wasSuccessful())
和一个测试用例结构(Invoice.py):
from selenium import selenium
import unittest, time, re
from setup_tests import filename, fileForNrTest, username, password, server_url
fileW=open(filename,'a')
class TestInvoice(unittest.TestCase):
def setUp(self):
self.verificationErrors = []
self.selenium = selenium("localhost", 4444, "*firefox", server_url)
self.selenium.start()
def test_invoice(self):
sel = self.selenium
[...]
def tearDown(self):
self.selenium.stop()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
unittest.main()
谢谢!
I need to make a big python suitecase consisted of other suitcases and testcase which I have already made to execute together.
How do I do this?
For example, here there is a suitecase (suiteFilter.py) which I want to add:
import testFilter1
import testFilter2
import unittest
import sys
def suite():
return unittest.TestSuite((\
unittest.makeSuite(testFilter1.TestFilter1),
unittest.makeSuite(testFilter2.TestFilter2),
))
if __name__ == "__main__":
result = unittest.TextTestRunner(verbosity=2).run(suite())
sys.exit(not result.wasSuccessful())
And a testcase structure (Invoice.py):
from selenium import selenium
import unittest, time, re
from setup_tests import filename, fileForNrTest, username, password, server_url
fileW=open(filename,'a')
class TestInvoice(unittest.TestCase):
def setUp(self):
self.verificationErrors = []
self.selenium = selenium("localhost", 4444, "*firefox", server_url)
self.selenium.start()
def test_invoice(self):
sel = self.selenium
[...]
def tearDown(self):
self.selenium.stop()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
unittest.main()
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以提供一些附加信息,例如程序/测试用例和套件的结构。我的方法是为每个模块定义一个 suite() 。所以我对 UserServiceTest 模块说:
然后我对每个包都有一个主要测试:
您可以递归地执行此操作,直到项目的根目录。因此,包 A 中的主测试将收集包 A 中的所有模块 + 包 A 的子包中的主测试,依此类推。我假设你正在使用
unittest
因为你没有提供任何额外的细节,但我认为这个结构也可以应用于其他 python 测试框架。编辑:嗯,我不太确定我完全理解你的问题,但据我所知,你想将 suiteFilter.py 中定义的套件和 Invoice.py 中定义的测试用例添加到同一个套件中?如果是这样,为什么不直接在 mainTest.py 中执行以下操作:
您可以将测试和套件添加到 test_suite 中。
You could give some additional information like the structure of your program / test cases and suites. The way I do it is define a suite() for each module. So I have say for UserServiceTest module:
Then I have a main test for each package:
You can do this the recursevly until the root of your project. So main test from package A will gather all module in package A + main test from subpackages of package A and so on. I was assuming you-re using
unittest
since you didn't give any additional details but I think this structure can be applied to other python testing frameworks as well.Edit: Well I'm not quite sure I fully understand your problem, but from what I can understand you want to add both the suite defined in suiteFilter.py and the testcase defined in Invoice.py in the same suite? If so why not just do in a mainTest.py for example:
You can add tests and suites all the same to a test_suite.