zoukankan      html  css  js  c++  java
  • vs.2008中如何对抽象类私有方法进行单元测试

          OleDbReader是个抽象类,用于封装通过OledDB基本方法,而ExcelOleDB是他的一个实现。而我测试一下抽象类中
    的私有方法GetData。开示的代码如下:

        
          PrivateObject param0 =new PrivateObject(new ExcelOledDBReader());
          OleDbReader_Accessor target = new OleDbReader_Accessor(param0);
          //some code...
          DataTable actual = target.GetData(filePath, top, columnInfos, skipLength);          
          Assert.AreEqual(10, actual.Rows.Count);
       

        但是发觉会报
        Test method FileSepc.Test.OleDbReaderTest.GetDataTest threw exception:  System.ArgumentException:
          The member specified (GetData) could not be found. You might need to regenerate your private accessor,
          or the member may be private and defined on a base class. If the latter is true, you need to pass the type
          that defines the member into PrivateObject's constructor.

        后来为praram0变量加上PrivateType类的实例后就可以啦。 代码如下:
         PrivateType type=new PrivateType(typeof(OleDbReader));
         PrivateObject param0 =new PrivateObject(new ExcelOledDBReader(),type);
         OleDbReader_Accessor target = new OleDbReader_Accessor(param0);
         //some code...
          DataTable actual = target.GetData(filePath, top, columnInfos, skipLength);          
          Assert.AreEqual(10, actual.Rows.Count);


    from:http://blog.csdn.net/luqizheng/article/details/2959768

  • 相关阅读:
    SQL-W3School-高级:SQL ALIAS(别名)
    SQL-W3School-高级:SQL BETWEEN 操作符
    SQL-W3School-高级:SQL IN 操作符
    SQL-W3School-高级:SQL 通配符
    C语言实现定积分求解方法
    android使用webview上传文件(支持相册和拍照)
    POJ2349+Prim
    nyist 740 “炫舞家“ST(动态规划)
    paip.php eclipse output echo 乱码
    Deep Learning论文笔记之(八)Deep Learning最新综述
  • 原文地址:https://www.cnblogs.com/SFAN/p/2153570.html
Copyright © 2011-2022 走看看