MSTest代码覆盖率与DataRows不起作用

时间:2018-01-08 16:23:51

标签: unit-testing code-coverage mstest datarow

我有一个简单的转换方法,从一个枚举到另一个。

public static ServiceStatus FromTheirState(TheirState fromState)
{
    MyStatus newStatus;

    switch (fromState)
    {
        case TheirState.Online:
            newStatus = MyStatus.Online;
            break;

        case TheirState.Intermittent:
            newStatus = MyStatus.Intermittent;
            break;

        case TheirState.Offline:
        default:
            newStatus = MyStatus.Offline;
            break;

    }

    return newStatus;
}

要对此进行单元测试,我正在执行以下操作

    [TestMethod]
    [DataRow(TheirState.Online, MyStatus.Online)]
    [DataRow(TheirState.Offline, MyStatus.Offline)]
    [DataRow(TheirState.Intermittent, MyStatus.Intermittent)]
    public void TestFromTheirState(TheirState state, MyStatus expectedStatus)
    {
        MyStatus actualStatus = StatusConverter.FromTheirState(state);
        Assert.AreEqual(expectedStatus, actualStatus);
    }

虽然测试结果显示所有3项测试都成功完成(见下文),但代码覆盖率表示“在线”案例是唯一涵盖的案例。其他两个转换案例未被覆盖。有任何想法吗?这是一个错误吗?

Hierarchy                   Not Covered (Blocks)    Covered (% Blocks) Not Covered (% Blocks)   Covered (Blocks)    
FromTheirState(TheirState)      2                       66.67 %            33.33 %                  4

测试结果:

测试名称:TestFromTheirState 测试FullName:Manager.TestServiceStatus.TestFromTheirState 测试结果:通过 测试时间:0:00:00.0072567

Result1名称:TestFromTheirState(Intermittent,Intermittent) 结果1结果:通过 结果1持续时间:0:00:00.0000028 Result1 StackTrace: Result1消息: Result1 StandardOutput: Result1 StandardError:

Result2名称:TestFromTheirState(离线,离线) 结果2结果:通过 结果2持续时间:0:00:00.0000278 Result2 StackTrace: 结果2消息: Result2 StandardOutput: Result2 StandardError:

Result3名称:TestFromTheirState(在线,在线) 结果3结果:通过 结果3持续时间:0:00:00.0072261 Result3 StackTrace: 结果3消息: Result3 StandardOutput: Result3 StandardError:

0 个答案:

没有答案