测试除一个特定组合之外的所有参数组合
test all combinations of parameters excluding one specific combination
我想创建测试所有参数组合的测试,不包括具有不同预期结果的一种组合。
到目前为止我想出了
[TestCase(false, false, ExpectedResult = false)]
[TestCase(false, true, ExpectedResult = false)]
[TestCase(true, false, ExpectedResult = false)]
[TestCase(true, true, ExpectedResult = true)]
public bool Test(bool paramA bool paramB)
{
var target = new MyComand(paramA, paramB);
return target.CanExecute();
}
// this class is made up, but shows the basic concept
public class MyCommand
{
bool _preConditionA;
bool _preConditionB;
public MyCommand(bool preConditionA, bool preConditionB)
{
_preConditionA = preConditionA;
_preConditionB = preConditionB;
}
public bool CanExecute()
{
if (_preConditionA == false)
return false;
if (_preConditionB == false)
return false;
return true;
}
}
或者有些疯狂[TestCaseSource]
。
这两种情况对我个人而言都存在可读性问题。
当参数不仅仅是布尔值时,这会变得更加复杂。
我检查了 [Values]
和 [Combinatorical]
属性,但它们并不真正适用于我的情况。
有人知道解决这个问题的其他方法吗?
Does anybody know any other way to solve this?
一种可能的解决方案是使用 Assumptions 跳过参数不会产生测试检查的 post 条件的组合。
我想创建测试所有参数组合的测试,不包括具有不同预期结果的一种组合。
到目前为止我想出了
[TestCase(false, false, ExpectedResult = false)]
[TestCase(false, true, ExpectedResult = false)]
[TestCase(true, false, ExpectedResult = false)]
[TestCase(true, true, ExpectedResult = true)]
public bool Test(bool paramA bool paramB)
{
var target = new MyComand(paramA, paramB);
return target.CanExecute();
}
// this class is made up, but shows the basic concept
public class MyCommand
{
bool _preConditionA;
bool _preConditionB;
public MyCommand(bool preConditionA, bool preConditionB)
{
_preConditionA = preConditionA;
_preConditionB = preConditionB;
}
public bool CanExecute()
{
if (_preConditionA == false)
return false;
if (_preConditionB == false)
return false;
return true;
}
}
或者有些疯狂[TestCaseSource]
。
这两种情况对我个人而言都存在可读性问题。
当参数不仅仅是布尔值时,这会变得更加复杂。
我检查了 [Values]
和 [Combinatorical]
属性,但它们并不真正适用于我的情况。
有人知道解决这个问题的其他方法吗?
Does anybody know any other way to solve this?
一种可能的解决方案是使用 Assumptions 跳过参数不会产生测试检查的 post 条件的组合。