【发布时间】:2013-04-09 20:26:15
【问题描述】:
我需要测试这个类:
public abstract class GaBase
{
protected GoogleAnalyticsInfo GAInfo;
protected abstract void PopulateGAInfo();
public string GetGoogleAnalyticsTag()
{
//Return any info related to GAInfo
}
//Some other stuffs
}
我需要对GetGoogleAnalyticsTag 方法进行单元测试,但我需要设置属性GAInfo 才能正确测试它。在生产代码中,当我们从此类派生时,我们使用我的PopulateGaInfo 方法来执行此操作。
如何使用存根设置GAInfo?
这是我的测试方法:
public void MyTest1()
{
var ga = new StubGaBase()
{
PopulateGAInfo01 = () =>
{
// How can I set GAInfo here?
}
};
// The method I need to test
var script = ga.GetGoogleAnalyticsTag();
// My asserts
}
【问题讨论】:
-
遮阳篷取决于您要测试的内容以及 GetGoogleAnalyticsTag() 方法的工作方式。如果没有实施,真的很难回答您的问题。
-
如果您想被称为 Benjamin/被称为 Benjamin,请更新您的个人资料,而不是将该信息放在您的问题中。
标签: .net unit-testing protected moles stubs