[英]How to determine what block isn't covered here?
I have a block of code like this (class/property names have been changed to meet company guidelines): 我有一个这样的代码块(类/属性名称已更改以满足公司准则):
if (output.ExecutionStatus == RuleExecutionStatus.Success &&
!obj.ListOfObjs.Cast<ConcreteType>().Any(p => p.Id == o.Id))
{
obj.AddConcreteType(output.ConcreteObj);
}
Before adding && !obj.ListOfObjs.Cast<ConcreteType>().Any(p => p.Id == o.Id)
this line was 100% covered. 在添加
&& !obj.ListOfObjs.Cast<ConcreteType>().Any(p => p.Id == o.Id)
此行已被100%覆盖。 I added one test, called Test 2
down below. 我在下面添加了一个测试,称为“
Test 2
。
So, after adding the new test, this block is almost 100% covered; 因此,在添加了新测试之后,几乎100%覆盖了该块; but I can't figure out what isn't getting covered.
但我无法弄清楚没有涵盖的内容。 It states
1
block is not covered. 它指出没有覆盖
1
块。 The tests executing now have the following attributes: 现在执行的测试具有以下属性:
0
in ListOfObjs
, no match, adds successfully. ListOfObjs
中为0
,不匹配,添加成功。 2
in ListOfObjs
, 1
matches on Id
, does not add. 2
在ListOfObjs
, 1
场比赛Id
, 不添加。 What I've Tried 我尝试过的
ListOfObjs
, no match, adds successfully. ListOfObjs
中具有1的测试(不匹配)会成功添加。 I thought maybe the issue was surrounding the fact that it didn't cover the Any
case where 0
matched. 0
匹配的Any
情况。 It sounds like you haven't got a test where the execution status isn't success - in other words, the first operand of your &&
expression is true
for all tests, so you're not checking that it's relevant. 这听起来像你没有一个测试,执行状态并不成功-换句话说,你的第一个操作数
&&
表达式是true
所有测试,这样你就不会检查它的相关性。
(In general, if you can remove some of your production code without any of your tests breaking, that's a bad sign - or it's a sign that it was non-functional, eg an optimization.) (通常,如果您可以在不破坏任何测试的情况下删除一些生产代码,则这是一个不好的信号-或表明它没有功能,例如优化)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.