我的代码是这样的:
class class1(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
def testListRolesTitle(self):
driver=self.driver
driver.get("www.google.com")
def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)
asert...
class class2(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
def testListRolesTitle(self):
driver=self.driver
driver.get("www.google.com")
assert...
def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)
def suite():
s1 = unittest.TestLoader().loadTestsFromTestCase(class1)
s2 = unittest.TestLoader().loadTestsFromTestCase(class2)
return unittest.TestSuite([s1,s2])
if __name__ == "__main__":
run(suite())
当我运行该套件时,两个测试类都在setup method中启动了一个新的firefox实例。 我的问题是,是否可以让两个测试类使用同一个firefox实例? 我不想把他们放在一个班里。在
有什么想法吗?在
您可以有一个应用于整个模块的setup函数,而不是像解释的那样只应用于类here。在
在你的情况下,应该是:
注意,
DRIVER
在本例中是一个全局变量,因此它对所有类的对象都可用。在另外,请注意,测试用例排序可能会导致多次调用模块设置函数,如文档中所述:
它认为这个例子应该说明每个设置方法/函数的执行时间:
^{pr2}$结果是:
相关问题 更多 >
编程相关推荐