我已成功使用以下方法来重置测试之间的期望:
MyMock.BackToRecord(BackToRecordOptions.Expectations);
MyMock.Replay();
但是,在第二个测试尝试在模拟方法上抛出异常的情况下,这似乎不起作用:
[SetUp]
public void Setup()
{
//reset expectations for each test
MockRestQuestionClient.BackToRecord(BackToRecordOptions.Expectations);
MockRestQuestionClient.Replay();
}
[Test]
public void Test1() {
MyMock.Expect(t => t.Something()).Returns(someObject);
}
[Test]
public void Test2() {
//this works when run individually, but fails if run after Test1
MyMock.Expect(t => t.Something()).Throw(new Exception());
}
任何想法我做错了什么?
谢谢!