zoukankan      html  css  js  c++  java
  • unittest参数化parameterized

    接口测试中,一个接口需要测试不同传参场景,每个场景写一个测试方法,会导致脚本冗长,查找修改时也不方便,可以使用unittest参数化parameterized模块,将传参参数化后,减少测试方法数量。

    具体用法:

    import unittest from nose_parameterized
    import parameterized, param
     
    class TestAdd(unittest.TestCase):
      @parameterized.expand([
        param("11", 11), param("10", 16, base=16),
      ])
      def test_int(self, str_val, expected, base=10):
      self.assertEqual(int(str_val, base), expected)
     
    if __name__ == '__main__':
    unittest.main()
     
     
    How to work:
    test_int会运行两组参数:
    第一组:(str_val=”11”, expected=11, base=10)
    第二组:(str_val=”10”, expected=16, base=16)
    即在@parameterized.expand的param中可以默认指定参数的值,且此值不会随方法的变量改变
    Stay hungry,stay foolish!
  • 相关阅读:
    9.13 h5日记
    9.12 h5日记
    9.11 h5日记
    9.10 h5日记
    H5笔记周记
    ASP.NET-GridView之表头设计
    论执行力
    BS总结篇­
    花样年纪的记录(一)
    Nginx+ISS+Redis实现完美负载均衡
  • 原文地址:https://www.cnblogs.com/justdo-it/p/11699237.html
Copyright © 2011-2022 走看看