import unittest
import requests
# 版一:
class MyTestCase(unittest.TestCase):
def setUp(self):
print("初始化")
def tearDown(self):
print("收尾")
def xxxTest(self):
print(11111)
if __name__ == '__main__':
obj = MyTestCase(methodName="xxxTest")
obj.run()
# 版二:
url = 'https://cnodejs.org/api/v1/topics'
class TestCase2(unittest.TestCase):
def setUp(self):
response = requests.get(url)
self.res = response.json()["success"]
def test_case_01(self):
print(111111, self.res)
# Self.assertEqual (True, res, msg = " expected value with the expected value {} {} does not match the" .format (False, RES))
self.assertTrue (self.res)
DEF test_case_02 (Self):
self.assertFalse (Self .res)
IF the __name__ == '__main__':
unittest.main ()
unittest is simple to use .py
Guess you like
Origin www.cnblogs.com/zhang-da/p/12240921.html
Recommended
Ranking