zoukankan      html  css  js  c++  java
  • Visual Studio 2008 进行单元测试之测试私有方法

    使用VS2008进行UnitTest 的步骤:

      1.在对象的私有方法单击右键;选择“Create Unit Tests...”

      2.生成测试代码;

      3.修改测试代码;

      4.测试;

     图示:

    1.略

    2.VS2008 生成的测试代码  

    代码
    /// <summary>
    ///A test for WhereFieldRelation
    ///</summary>
    [TestMethod()]
    [DeploymentItem(
    "AIIMS.DBUtility.dll")]
    public void WhereFieldRelationTest1()
    {
    PrivateObject param0
    = null; // TODO: Initialize to an appropriate value
    CreateSqlQuery_Accessor target = new CreateSqlQuery_Accessor(param0); // TODO: Initialize to an appropriate value
    QueryItem item = null; // TODO: Initialize to an appropriate value
    string expected = string.Empty; // TODO: Initialize to an appropriate value
    string actual;
    actual
    = target.WhereFieldRelation(item);
    Assert.AreEqual(expected, actual);
    }

    3.修改测试代码

    代码
    /// <summary>
    ///A test for WhereFieldRelation
    ///</summary>
    [TestMethod()]
    [DeploymentItem(
    "AIIMS.DBUtility.dll")]
    public void WhereFieldRelationTest()
    {
    //
    //声明私有方法所属类的类型
    //
    PrivateType type = new PrivateType(typeof(CreateSqlQuery));
    //
    //声明PrivateObject对象,参数为对象实例instance和类型type
    //
    PrivateObject param0 = new PrivateObject(new CreateSqlQuery("Popedom"), type);
    //
    //实例化被测试类的一个对象(target即为CreateSqlQuery类的一个对象)
    //
    CreateSqlQuery_Accessor target = new CreateSqlQuery_Accessor(param0);

    QueryItem item
    = new QueryItem();
    item.FieldName
    = "PopedomName";
    item.FieldValue
    = "天通苑北二区";
    string expected = "PopedomName = '天通苑北二区'";
    string actual;
    //
    // 调用被测试方法,取得实际返回值
    //
    actual = target.WhereFieldRelation(item);
    Assert.AreEqual(expected, actual);
    }

  • 相关阅读:
    [HAOI2015] 按位或
    [CF662C] Binary Table
    逻辑、集合运算上的卷积一览(FMT、FWT,……)
    从零开始的伯努利数
    [LGP2000] 拯救世界
    [BZOJ4180] 字符串计数
    [清华集训2017] 生成树计数
    [CF911G] Mass Change Queries
    微信公众号服务器配置(校验)
    mariadb数据库通过.ibd恢复过程(知道数据库结构的情况下)
  • 原文地址:https://www.cnblogs.com/bobbychencj/p/1756493.html
Copyright © 2011-2022 走看看