软件自动化测试—代码覆盖率

本文介绍了如何查看和使用代码覆盖率进行软件自动化测试。通过创建单元测试用例,利用Visual Studio进行代码覆盖率分析,展示了如何启用测试并查看结果。强调代码覆盖率虽能指示测试覆盖程度,但无法评估测试质量,且覆盖率100%不一定意味着所有场景都被测试到。
摘要由CSDN通过智能技术生成

软件自动化测试代码覆盖率

<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;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值