Summarizes the matters needing attention in the use of interface test unittest

## is mainly to record and see for yourself. . . . .
Summarizes the points to note when using the interface test unittest:
1) SetUp(self) and TearDown(self) only need to be written once, but each time test_case is executed, it must be executed once:
class TestUnittest11(unittest.TestCase):
def setUp (self):
print(“Initialize”)
def test_case1(self):
print(“test_case1”)
def test_case2(self):
print(“test_case2”)
def tearDown(self):
print(“Destroy”)
if name == ' main ':
unittest.main()
2) Initialized upgraded version of setUpClass(cls) and tearDownClass(cls), only need to be written once, and executed once in the entire class, but the decorator @classmethod
class TestUnittest22(unittest .TestCase):
@classmethod
def setUpClass(cls):
print("Initialize")
def test_case1(self):
print("test_case1")
def test_case2(self):
print("test_case2")
@classmethod
def tearDownClass(cls):
print("destroy")
3) Introduce the class OtherClass from other files in other.py in the main file, for example : There is OtherClass class in other.py<

Guess you like

Origin blog.csdn.net/qq_37405087/article/details/109990537