初始化、跳过测试用例

# test_class_6.py

import unittest
from mock import mock
from day_20200208_mooc.base.interface_request_class_5 import RunMain

class TestMethod(unittest.TestCase):
    def setUp(self):
        # 避免每个用例都去执行一次实例化
        self.run = RunMain()

    def test_01(self):
        url = ""
        data = ""
        # 把data作为mock.Mock的返回值
        mock_data = mock.Mock(return_value=data)
        # 把mock_data作为self.run.run_main方法的返回值
        self.run.run_main = mock_data
        res = self.run.run_main(url, "method", data)
        self.assertEqual(res["errorCode"], "期望值 ", "这是期望值和预期值不相等时给出的提示语")

    # 指定要跳过的测试用例,传入测试用例名,该用例不会执行
    @unittest.skip("test_02")
    def test_02(self):
        url = ""
        data = ""
        res = self.run.run_main(url, "method", data)

if __name__ == "__main__":
    suite = unittest.TestSuite()
    # 添加测试用例
    suite.addTest(TestMethod("test_01"))
    suite.addTest(TestMethod("test_02"))
    runner = unittest.TextTestRunner()
    runner.run(suite)
05-28 15:48