【发布时间】:2016-03-12 13:22:47
【问题描述】:
我的旧代码包含的代码看起来有点像这样:
public bool Execute(MyArgument arg)
{
if(arg.Condition)
{
switch(arg.Data)
{
case DataValue.A:
case DataValue.B:
case DataValue.C:
return false;
case DataValue.F:
case DataValue.G:
case DataValue.H:
return true;
}
}
else
{
arg.DoSomeStuff();
return true;
}
}
我们正在使用 Given-When-Then 模式,我的问题是我是否应该使用以下测试对其进行测试:
Given NewContext 当执行条件为 True 和 DataValue A Then 返回错误
Given NewContext 当执行条件为 True 和 DataValue B Then 返回错误
Given NewContext 当执行条件为 True 和 DataValue C Then 返回错误
Given NewContext 当执行条件为 True 和 DataValue D Then 返回真
Given NewContext 当执行条件为 True 和 DataValue E Then 返回真
Given NewContext 当执行条件 True 和 DataValue F Then 返回真
在条件为 False 的情况下执行时给定 NewContext 然后 DoSomeStuff 应该调用然后返回true
或者你有什么更好的方法吗? (如果您认为我的测试是有效的,请不要犹豫在 cmets 中这样说)。
【问题讨论】:
-
感谢您的评论,我们正在使用 NUnit 和 NSubstitute。
标签: c# unit-testing testing legacy-code