#unittest-test.py
import unittest
from demo import RunMain
import HtmlTestRunner
class TestMethod(unittest.TestCase):
#类方法
@classmethod
def setUpClass(cls):
print("类执行之前的方法")
@classmethod
def tearDownClass(cls):
print("类执行之后的方法")
#每次方法之前执行
def setUp(self):
print("setup")
def test_01(self):
url_p = "https://easy-mock.com/mock/5d0cce9536b12b2b2e62adc7/example/upload"
data = {
"hello":"world",
"botoo":"123"
}
res = RunMain(url_p,"POST",data).res
#print(res)
self.assertIn("undefined_http",str(res['data']))
globals()['img'] = res['data']['img'] #加入缓存
def test_02(self):
print(img)
url_g ="https://easy-mock.com/mock/5d0cce9536b12b2b2e62adc7/example/query"
res = RunMain(url_g,"GET").res
self.assertEqual("hah",res['data']['name'])
#print(res)
@unittest.skip
def test_03(self):
print(img)
#每次方法之后执行
def tearDown(self):
print("teardown")
if __name__ == "__main__":
"""
#方法一:
unittest.main()
"""
"""
#方法二:
#加入容器中执行
suite=unittest.TestSuite()
suite.addTest(TestMethod("test_01"))
suite.addTest(TestMethod("test_02"))
suite.addTest(TestMethod("test_03"))
unittest.TextTestRunner().run(suite)
"""
"""
#方法三:
#加入测试报告,执行所有case
unittest.main(testRunner=HtmlTestRunner.HTMLTestRunner(output='example_dir'))
"""
"""
#方法四:
#加入测试报告,执行加入容器的case
suite = unittest.TestSuite()
suite.addTest(TestMethod("test_01"))
suite.addTest(TestMethod("test_02"))
suite.addTest(TestMethod("test_03"))
testRunner=HtmlTestRunner.HTMLTestRunner(output='example_dir')
testRunner.run(suite)
"""