Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 单元测试可能性矩阵_Python_Unit Testing_Testing_Automated Tests_Code Coverage - Fatal编程技术网

Python 单元测试可能性矩阵

Python 单元测试可能性矩阵,python,unit-testing,testing,automated-tests,code-coverage,Python,Unit Testing,Testing,Automated Tests,Code Coverage,我正在尝试为定义如下的某个类(python)的方法编写单元测试: cond1到cond5是表示某些业务逻辑的布尔值。由于存在5个布尔值,因此可能出现32种情况。我通过定义所有可能性和预期结果矩阵实现了我的单元测试,如下所示: # matrix of tuples of (cond1, cond2, cond3, cond4, cond5, result) matrix = [ (True, True, True, True, True, True), (True, True, T

我正在尝试为定义如下的某个类(python)的方法编写单元测试:

cond1
cond5
是表示某些业务逻辑的布尔值。由于存在5个布尔值,因此可能出现32种情况。我通过定义所有可能性和预期结果矩阵实现了我的单元测试,如下所示:

# matrix of tuples of (cond1, cond2, cond3, cond4, cond5, result)
matrix = [
    (True, True, True, True, True, True),
    (True, True, True, True, False, True),
    .
    .
    # 32 tuples in total
]
定义完这个矩阵后,我在元组上迭代,根据每个元组中的前5项(
cond1
cond5
)构造对象,调用构造对象上的方法,然后断言结果等于元组的最后一项(
result
)。该策略成功地测试了每种情况,并涵盖了所有可能性

我的问题是关于在这种情况下应遵循的惯例和最佳做法。我认为我的方法对于编写unittest来说太复杂了,尽管它涵盖了所有可能的情况。你能提出更好的策略吗

p.S.如果您能为我指出编写更好的单元测试所需的资源(最好是书),我将不胜感激。

如果您能列举所有可能的输入,并在可接受的时间内对所有输入运行测试,我说加油。测试的输入总是比未测试的输入好。
# matrix of tuples of (cond1, cond2, cond3, cond4, cond5, result)
matrix = [
    (True, True, True, True, True, True),
    (True, True, True, True, False, True),
    .
    .
    # 32 tuples in total
]