【发布时间】:2019-12-09 12:40:53
【问题描述】:
我有课
public class MyClass
{
public int MyProperty1 { get; private set; }
public int MyProperty2 { get; private set; }
public MyClass(){}
public MyClass(int myProperty2) => MyProperty2 = myProperty2;
}
在我的单元测试中,我需要在做出如下断言之前更改 MyProperty1 的值
[Fact]
public void MyTest()
{
var fake = NSubstitute.Substitute.For<MyClass>(3);
fake.MyProperty1.Returns(5);
//Assertion
}
但是我得到了错误
Outcome: Failed
Error Message:
NSubstitute.Exceptions.CouldNotSetReturnDueToNoLastCallException : Could not find a call to return from.
【问题讨论】:
-
这可能是XY problem。我的第一个问题是你为什么要这么做?你到底想测试什么?
标签: c# unit-testing .net-core mocking nsubstitute