What Constitutes a Code Block in Visual Studio 2010?
As per MSDN:
A code block is a code path with a single entry point, a single exit point, and a set of instructions that are all run in sequence. A code block ends when it reaches a decision point such as a new conditional statement block, a function call, exception throw, enter, leave, try, catch, or a finally construct.
With this in mind, I still have no idea why, according to VS2010's code coverage analysis, this method has three blocks:
public Type Foo()
{
return typeof(string);
}
And this method has two blocks:
public void FooTwo()
{
return;
}
Code lines ar开发者_开发百科e more straightforward. They're the number of lines of code including curly brackets. But what are code blocks?
Calvin
Code blocks mean contiguous paths at the Common Intermediate Language / Microsoft Intermediate Language level. This is unfortunately not mentioned in the MSDN article above.
Good explanations from Microsoft gurus themselves here:
http://www.testingmentor.com/imtesty/2009/11/18/basic-blocks-arent-so-basic/
http://blogs.msdn.com/b/scarroll/archive/2005/01/14/353427.aspx?wa=wsignin1.0
In a nutshell it doesn't make sense to meticulously count CIL code blocks. They're on a different plane than the code we write, and they can even vary depending on whether your compilation is Debug or Release.
精彩评论