单元测试-测试类-test_api

import unittest
from API_AUTO.tools.http_request import HttpRequest


class TestLogin(unittest.TestCase):
    def setUp(self):
        print("开始执行测试用例")

    def tearDown(self):
        print("用例执行完毕")

    def __init__(self, methodName, url, method, data, expected):
        super(TestLogin, self).__init__(methodName)
        self.url = url
        self.method = method
        self.data = data
        self.expected = expected

    def test_api(self):
        res = HttpRequest().http_request(self.url, self.method, self.data)
        r = res.json()["info"]
        try:
            self.assertEqual(r, self.expected)
        except AssertionError as e:
            print("test_case‘s error is {}".format(e))
            raise e  # 处理异常后抛出去,才能被检测到用例失败了


if __name__ == ‘__main__‘:
    unittest.main()

  

单元测试-测试类-test_api

上一篇:SDNU_ACM_ICPC_2020_Winter_Practice_1st


下一篇:Windows 10优化之右键灰色SkyDrive Pro(S)