• python_unittest



    class_01
    # @Email:zhaoy201810@126.com
    # @Time: 2020/12/4 15:44
    # @file: class_01.py
    # 单元测试的框架 unitest +接口 pytest+web--->>接口
    # pytest + jenkins + allure
    # 功能测试
    # 1.测试用例 写TestCase
    # 2.执行测试用例 1.TestSuite 2.TestLoader 找用例加载用例,存到1的TestSuite里面
    # 3.对比预期结果与实际结果,判定用例是否通过 #断言 Assert
    # 4.出具测试报错 TextTestRunner

    class MathMethod():
    def __init__(self,a,b):
    self.a = a
    self.b = b
    def add(self):
    return self.a+self.b
    def muti(self):
    return self.a * self.b
    import unittest
    # 下一个测试类,对我们自己写的math_method模块进行单元测试
    class TestMathMethod(unittest.TestCase):# 继承了unittest的TestCase,专门写测试用例


    # 编写测试用例
    # 一个用例就是一个函数,不能传参
    # 所有的用例都是test开头
    def test_add_two_posttive(self):
    res = MathMethod(1,1).add()
    print("1+1的结果值是:",res)

    def test_add_two_zero(self):
    res = MathMethod(0,0).add()
    print("1+1的结果值是:",res)

    def test_add_two_native(self):
    res = MathMethod(-1,-2).add()
    print("1+1的结果值是:",res)

    def test_multi_two_postive(self):
    res = MathMethod(1,1).muti()
    print("1*1的结果是:",res)

    def test_muti_two_zero(self):
    res = MathMethod(0,0).muti()
    print("0*0的结果是:",res)

    def test_muti_two_negative(self):
    res = MathMethod(-2,-3).muti()
    print("-2乘以-3的结果是:",res)

    if __name__ == '__main__':
    unittest.main

    # ASCII编码
    # posttive 2
    # zero 3
    # native 1
    # abcdefghijklmnopqrstuvwxyz

    class_02
    # @Email:zhaoy201810@126.com
    # @Time: 2020/12/4 16:13
    # @file: class_02.py
    import unittest
    from API_AUTO.tools.class_01 import TestMathMethod

    suite =unittest.TestSuite()

    # 只执行一条
    # 模块外用到的话,需要创建实例 -- 第一种加载方法
    # suite.addTest(TestMathMethod('test_add_two_posttive')) # 存储用例
    # # 执行
    # runner = unittest.TextTestRunner()
    # runner.run(suite)

    # 方法二 TestLoader
    loader = unittest.TestLoader()
    # suite.addTest(loader.loadTestsFromTestCase(TestMathMethod))
    from API_AUTO.tools import class_01
    suite.addTest(loader.loadTestsFromModule(class_01))

    runner = unittest.TextTestRunner()
    runner.run(suite)

    我的博客即将同步至腾讯云+社区,邀请大家一同入驻:https://cloud.tencent.com/developer/support-plan?invite_code=1bej86x0我的博客即将同步至腾讯云+社区,邀请大家一同入驻:https://cloud.tencent.com/developer/support-plan?invite_code=1bej86x0opcmh
    纸上得来终觉浅,绝知此事要躬行
  • 相关阅读:
    cd 好吃的 收藏
    2011 无代码无意义…test 指针 v1
    转 云中漫步的 电子书 from simon
    2011无代码无意义 test_gets_scanf连用 等
    svn—relocate 的原因
    转 CString,string,char*的综合比较
    2011 无代码无意义 test_内存之 变量的边界 (图)
    转 解决"应用程序配置不正确,程序无法启动"
    转 删除已存在的SVN账户信息
    C#中IO类FileInfo和Directory操作实例
  • 原文地址:https://www.cnblogs.com/testing2018/p/14088738.html
Copyright © 2020-2023  润新知