Block:A sequence of non-branching statements; a linear sequence of code with no control flow route branchings.
Block coverage
Block coverage, sometimes known as line coverage, describes whether a block of code, defined as not having any branch point within (i.e. the path of execution enters from the beginning and exits at the end) is executed or not.
Block到底如何计算?
其实,我们说Block覆盖率是针对目标码而言,而不是源代码。这在Line Coverage中有提到过。一个Block是说一个机器码片段的基本控制流的单个进和单个出。因此,一个调用语句的使用可以看作是一个Blcok结束的标志。
Example:
int main()
{
1: BasicClass A;
2: int i = 10;
3: if (i)
4: {
5: i = A.function();
6: }
7: return i;
}
在上面的例子中,你觉得会有几个Block?
一相当部分的人会觉得是3个。其实不然。
第一行中BasicClass类对构造函数和析构函数(之后)的调用,第5行中对function()的调用以及i返回值的分配。
参考:
http://www.51testing.com/?uid-264206-action-viewspace-itemid-129974