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

  • 相关阅读:
    Beta版软件说明书
    团队项目第五天
    cnblogs用户体验评价
    团队项目测试计划
    Alpha版总结会议
    软件使用说明书
    团队绩效考核
    各个小组对于“我爱淘”的评价
    软件工程团队项目评价
    丹佛机场行李系统处理方案
  • 原文地址:https://www.cnblogs.com/bobbychencj/p/1756493.html
Copyright © 2011-2022 走看看