zoukankan      html  css  js  c++  java
  • paramunittest参数化测试基础

    samples:

    import paramunittest
    import unittest

    @paramunittest.parametrized(
    (10,20),
    (30,40),
    # (100,20)
    )
    class ApiTestDemo(paramunittest.ParametrizedTestCase): #unittest.TestCase
    def setParameters(self, numa,numb):
    self.a = numa
    self.b = numb
    def test_add_case(self):
    print( '%d+%d?=%d'%(self.a,self.b,30) )
    self.assertEqual( self.a + self.b,30 )

    if __name__=='__main__':
    unittest.main(verbosity=2)
    前面定义的是字典,那参数就跟前面字典的key保持一致.
     

    demo_09.py

    import paramunittest
    import unittest

    @paramunittest.parametrized(
    {'numa':10,'numb':30},
    {'numa':40,'numb':50}
    )
    class ApiTestDemo(paramunittest.ParametrizedTestCase):
    def setParameters(self, numa, numb):
    self.a = numa
    self.b = numb
    def test_add(self):
    print('%d+%d?=%d' % (self.a, self.b, 40))
    self.assertEqual(self.a + self.b, 40)

    if __name__=='__main__':
    unittest.main(verbosity=2)

    把数据移出去:

    参考:

    demo_10.py

    import paramunittest
    import unittest
    test_data = [{'numa':10,'numb':30},{'numa':40,'numb':50}]
    def get_data():
    return test_data
    @paramunittest.parametrized(
    *get_data()
    )
    class ApiTestDemo(paramunittest.ParametrizedTestCase):
    def setParameters(self, numa, numb):
    self.a = numa
    self.b = numb
    def test_add(self):
    print('%d+%d?=%d' % (self.a, self.b, 40))
    self.assertEqual(self.a + self.b, 40)

    if __name__=='__main__':
    unittest.main(verbosity=2)
    回忆滋润坚持
  • 相关阅读:
    Centos7LDAP LDAPadmin的完整部署记录(改良版,其它文档太多坑)
    linux weblogic11g 部署
    redis离线集群安装
    Weblogic11g 10.3部署
    jdk安装部署
    tar.xz文件如何解压
    linux-Centos7安装python3并与python2共存
    ssh免密码登录配置方法
    Docker容器安装weblogic详细教程
    linux命令分块总结---多操作才是真理
  • 原文地址:https://www.cnblogs.com/james5d/p/14126969.html
Copyright © 2011-2022 走看看