【发布时间】:2013-03-20 17:56:49
【问题描述】:
我正在使用 AutoFixture 为我的 Abstract 类编写单元测试,这代表了我正在尝试做的事情:
public abstract class Base
{
public virtual void DoSomethingCool()
{
OnDoingSomethingCool();
}
protected abstract void OnDoingSomethingCool();
}
我的单元测试如下所示:
[TestMethod]
public void TestMethod1()
{
var fixture = new Fixture().Customize(new AutoMoqCustomization());
var sut = fixture.Create<Base>();
// How to assert that the OnDoingSomethingCool method was called
sut.Invoking(x => x.DoSomethingCool())
.ShouldNotThrow();
}
那么我如何断言受保护的抽象方法实际上是在DoSomethingCool 方法中调用的呢??
如果它是来自注入依赖项的对象,我将能够使用Moq 设置一个模拟并断言该方法已被调用,但由于该方法是一个抽象方法在我的被测主题内,我如何断言该方法被调用?
【问题讨论】:
-
您使用 AutoFixture 作为Auto-mocking Container,但这确实是关于起订量的问题。
标签: c# unit-testing moq autofixture