软件自动化测试—代码覆盖率
在<professional software testing with visual studio 2005 team system tools for software developer>中提到了代码覆盖率,我很久没有去书店了,不知道是不是出了新的版本,觉得书里面关于代码覆盖率方面的知识有些地方没有讲,在这里补充一下。先回顾一下如何
查看代码覆盖率
创建一个C#工程WildChar(无所谓是类型库工程还是命令行程序工程),假设我们要写一个将字符串按单词成对反转的程序。将下面的代码贴到工程的一个cs文件中:
Program.cs
public static string ReverseStringPair(string input) { if (string.IsNullOrEmpty(input)) throw new ArgumentNullException("input");
char[] result = new char[input.Length]; int resultIter = 0;
ReverseStringPairImp(input, 0, result, resultIter);
return new string(result); }
private static void ReverseStringPairImp(string input, int inputIter, char[] result, int resultIter) { // skip white space while (inputIter < input.Length && input[inputIter] == ' ') inputIter++;
int[] indics = new int[2] { inputIter, // first word begin index, 0 // second word begin index };
for (; inputIter < input.Length; ++inputIter) { if (input[inputIter] == ' ') { if (indics[1] == 0) indics[1] = -1; else if (indics[1] > 0) break; } else if (input[inputIter] != ' ' && indics[1] == -1) indics[1] = inputIter; }
// copy second word, inputIter points to the end of second word if (indics[1] > 0) { for (int i = indics[1]; i < inputIter; ++i) result[resultIter++] = input[i];
indics[1]--; // copy white space while (indics[1] >= 0 && input[indics[1]] == ' ') indics[1]--;
result[resultIter++] = ' '; } else indics[1] = input.Length - 1; |