none
VS2010 code coverage 中的blocks到底是怎样看的? RRS feed

  • Question

  •         public static int MyCompare(int a, int b)
            {
                if (a == b)
                    return 0;
                else if (a > b)
                    return 1;
                else
                    return -1;
            }

     

    我为这个方法建立了一个unit test,

    [TestMethod()]
    public void MyCompareTest()
    {
    int a = 0; // TODO: Initialize to an appropriate value
    int b = 0; // TODO: Initialize to an appropriate value
    int expected = 0; // TODO: Initialize to an appropriate value
    int actual;
    actual = Class1.MyCompare(a, b);
    Assert.AreEqual(expected, actual);
    //Assert.Inconclusive("Verify the correctness of this test method.");
    }

    配置测试后查看code coverage,

    MyCompare(int32,int32) 3 50.00 % 3 50.00 % 

    其中两个3分别是not covered blocks 和 covered blocks。现在我改变我的原方法:

    public static int MyCompare(int a, int b)
    {
     if (a == b)
      return 0;
     else if (a > b && (a > 0))
      return 1;
     else if (a > b && !(a > 0))
      return 2;
     else
      return -1;
    }

     

    code coverage如下:

    MyCompare(int32,int32) 11 78.57 % 3 21.43 %

    请问not covered的blocks怎么变成11个了?怎么看的呢?谢谢

     

    Monday, July 18, 2011 8:24 AM

Answers

All replies