zoukankan      html  css  js  c++  java
  • ddt读取json文件测试用例的执行顺序

    一. 源码的说明

    在源码中,ddt的file_data函数下有这样一段话

    意思是说,如果json文件的内容是字典,字典的键名将会作为测试用例名的后缀,字典的值将会作为测试数据,如果这样的话,如果键名字母排序靠前的是不是先执行,字母排序靠后的是不是后执行?

    二. 验证猜想

    我们来验证一下,先新建一个my.json文件

    {"name":"nick","gender":"male","age":"29"}

    再新建一个测试用例类test_class_ddt.py

    import ddt
    import unittest
    
    @ddt.ddt
    class test_ddt(unittest.TestCase):
    
        @ddt.file_data(r"D:python_workshoppython6
    evisefutureloan_API_frameworkmy.json")
        def test_readData_fromJsonFile(self, a):
            """In case of a dict, keys will be used as suffixes to the name of the
            test case, and values will be fed as test data.
            如果文件的内容是一个字典,键名将作为测试用例的后缀,值将作为测试数据"""
            print("从文件读取数据")
            print(a)

    最后创建一个主函数,生成html测试报告

    import unittest
    from revise.futureloan_API_framework.test_class_ddt import test_ddt
    import time, os
    from HTMLTestRunnerNew import HTMLTestRunner
    
    suite = unittest.TestSuite()
    loader = unittest.TestLoader()
    suite.addTests(loader.discover(os.getcwd()))
    
    now = time.strftime("%Y-%m-%d_%H-%M-%S")
    fs = open(os.getcwd() + "/DDT_Test_Report_{0}.html".format(now), "wb")
    
    runner = HTMLTestRunner(stream=fs, title="DDT Test Report", tester="xiaozhai")
    runner.run(suite)

    三. 观察结果

    总共运行了3次测试用例,生成了3个测试报告,的确,源码说的key会追加到测试用例名后面作为后缀,这个情况是存在的,但运行的顺序却是随机的(可能因为字典是无序的吧)

    第一次测试报告

    第二次测试报告

    第三次测试报告

  • 相关阅读:
    iOS sqlite3
    NSObject常用方法
    驱动项目设置中混淆点小记
    globalsign代码签名最新步骤
    Web学习资源及手册查询整理
    H5基于iScroll实现下拉刷新,上拉加载更多
    移动端meta标签
    一、开发过程中遇到的js知识点总结(1)
    vue API 知识点(4) --- 指令、特殊 attribute 、内置组件
    vue API 知识点(3) --- 实例 总结
  • 原文地址:https://www.cnblogs.com/my_captain/p/9318626.html
Copyright © 2011-2022 走看看