zoukankan      html  css  js  c++  java
  • 3.runTest内部原理.py

    import requests
    import unittest


    class MyTestCase(unittest.TestCase):
    '''
    类名可以自定义
    但必须继承 unittest.TestCase

    在测试用例执行之前
    要做一些事情或者进行一些初始化的操作
    在测试用例执行之后,做一些收尾的操作

    '''

    def setUp(self):
    """ 在测试用例执行之前执行的方法 """

    self.response = requests.get(url='http://www.neeo.cc:6002/pinter/com/getSku?id=1')
    print("在测试用例执行之前触发我执行", self.response.json())

    def tearDown(self):
    """ 在测试用例执行之后执行的方法 """
    print("在测试用例执行之后触发我执行")
    del self.response

    def aaa(self):
    """ runTest就是测试用例 """
    if self.response.json()['message'] == "success":
    print('用例通过')
    else:
    print('用例执行失败')

    class MyTestCase2(unittest.TestCase):
    '''
    类名可以自定义
    但必须继承 unittest.TestCase

    在测试用例执行之前
    要做一些事情或者进行一些初始化的操作
    在测试用例执行之后,做一些收尾的操作

    '''

    def setUp(self):
    """ 在测试用例执行之前执行的方法 """
    data = {"userName": "admin", "password": 1234}
    self.response = requests.post(url='http://www.neeo.cc:6002/pinter/com/login',data=data)
    print("在测试用例执行之前触发我执行", self.response.json())

    def tearDown(self):
    """ 在测试用例执行之后执行的方法 """
    print("在测试用例执行之后触发我执行")
    del self.response

    def runTest(self):
    """ runTest就是测试用例 """
    if self.response.json()['message'] == "success":
    print('用例通过')
    else:
    print('用例执行失败')




    if __name__ == '__main__':
    case_obj = MyTestCase(methodName='aaa')
    case_obj.run()
    case_obj2 = MyTestCase2()
    case_obj2.run()

    在父类(unittest.TestCase)中的初始化方法的methodName参数,来控制我们测试用例的名称:

  • 相关阅读:
    linux-centos7安装mysql5.6
    CentOS Linux 7.2相关配置 以及环境搭建
    centos中查找占用磁盘大文件
    记录Redis在Windows下的安装与服务管理报错:Redis service failed to start.
    Spring cloud ----- 服务治理
    Spring Cloud技术分析
    Linux常用命令总结
    Java面试题总结(不断更新中)
    SpringBoot几种定时任务的实现方式
    Java 定时任务---Timer
  • 原文地址:https://www.cnblogs.com/zhang-da/p/12291566.html
Copyright © 2011-2022 走看看