Unittest method - test firmware (TestFixture)

Front and rear

1.setUp: write test cases when, in fact, are based on open your browser and enter the URL corresponding to these operations, this is the implementation of the pre-conditions for the use case of each operation.
2.tearDown: After execution cases, in order not to affect the execution of a next embodiment, the data reduction process are generally, this is an example of a post-execution conditions.

3. The front and rear are non-necessary conditions, if not you can write pass

import unittest
class Fass(unittest.TestCase):
def setup(self):
print("已经准备好了")

def tearown(self):
print("已处理")

def test001(self):
print("test")

def test002(self):
print("Teacher")

if __name__ == '__main__':
unittest.main(verbosity=2)

1.setupclass: write test cases when the operation is performed only once in fact, are based on open your browser and enter the URL corresponding to these operations, this is the implementation of the pre-conditions of use cases.
2.tearDownclass: After execution cases, close the browser operations to restore the data, which is an example of a post-execution conditions.

3. The front and rear are non-necessary conditions, if not you can write pass

import unittest
from selenium import webdriver

class F3(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.driver = webdriver.Chrome()
cls.driver.maximize_window()
cls.driver.implicitly_wait(30)
cls.driver.get("http://www.baidu.com")

@classmethod
def tearDownClass(cls):
cls.driver.quit()

def test_baidu_new(self):
self.driver.find_element_by_link_text("新闻").click()
self.driver.back()

def test_baidu_map(self):
self.driver.find_element_by_partial_link_text("图").click()
self.driver.back()

if __name__ == "__main__":
unittest.main(verbosity=2)

Guess you like

Origin www.cnblogs.com/Teachertao/p/11183464.html