vs.2008中如何对抽象类私有方法进行单元测试
2011-08-25 17:30
507 查看
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
的私有方法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
相关文章推荐
- vs.2008中如何对抽象类私有方法进行单元测试
- vs.2008中如何对抽象类私有方法进行单元测试
- 如何通过java反射的方式对java私有方法进行单元测试
- Visual Studio 2008 进行单元测试之测试私有方法
- 如何对私有方法进行单元测试?(依据推荐等级排序)
- 如何在VS中测试一个抽象类中的私有方法
- 如何给一个私有方法做单元测试
- 在单元测试中如何测试私有的方法
- Visual Studio 进行单元测试时如何附加被测试文件的方法总结
- 如何对类中的protected方法进行单元测试
- 在单元测试中如何测试私有方法
- 如何给一个私有方法做单元测试
- 如何进行Android单元测试
- 如何在Visual Studio 2005或者Visual Studio 2008里实现拖动控件进行绝对定位?
- 如何进行字符串循环替换的方法?
- 使用Angular CLI进行单元测试和E2E测试的方法
- SSH中如何进行单元测试
- 首页文章分类 关于 Search private(私有)方法单元测试无法覆盖?那就用反射调用来测试private(私有)方法
- obj-c中如何定义类的私有实例方法
- 如何访问python类中的私有方法