parameterized扩展了py.test参数化测试,unittest参数化测试。

 <1>一个小练习

import unittest
import math

@parameterized([
    (2, 2, 4),
    (2, 3, 8),
    (1, 9, 1),
    (0, 9, 0),
])
def test_pow(base, exponent, expected):
    assert_equal(math.pow(base, exponent), expected)

class TestMathUnitTest(unittest.TestCase):
    @parameterized.expand([
        ("negative", -1.5, -2.0),
        ("integer", 1, 1.0),
        ("large fraction", 1.6, 1),
    ])
    def test_floor(self, name, input, expected):
        assert_equal(math.floor(input), expected)
View Code

相关文章:

  • 2021-10-24
  • 2021-11-23
  • 2021-08-08
  • 2022-01-06
  • 2021-10-28
  • 2022-12-23
  • 2022-12-23
  • 2021-12-12
猜你喜欢
  • 2022-12-23
  • 2021-09-10
  • 2021-12-29
  • 2021-11-16
  • 2021-04-04
  • 2021-11-07
  • 2021-07-30
相关资源
相似解决方案