我想单元测试使用Moq。下面是示例代码:如何使用Moq设置只读属性?
public class ConcreteClass
{
private readonly FirstPropery firstProperty;
private readonly SecondProperty secondProperty;
public ConcreteClass(firstProperty, secondProperty)
{
this.firstProperty = firstProperty;
this.secondProperty = secondProperty;
}
}
[TestMethod]
var concreteClassMock = new Mock<ConcreteClass>() { CallBase = true };
在我的测试方法,我想设置firstProperty
引用一个真正的对象FirstProperty
对象(由工厂创建的),后来又用它来测试另一个对象的行为。有什么办法可以实现吗?
您不要模拟私人内容。模拟应该独立于某些实现。 – poke