Reset mock verification in Moq?

前端 未结 8 1681
执笔经年
执笔经年 2021-02-11 12:01

Setup as so:

public interface IFoo
{
    void Fizz();
}

[Test]
public void A()
{
    var foo = new Mock(MockBehavior.Loose);

    foo.Object.Fizz();         


        
8条回答
  •  自闭症患者
    2021-02-11 12:33

    I have also witnessed the Times.Exactly(1) verification failure across unit tests using MoQ, with a "was called 2 times" error message. I see this as a bug in MoQ, as I would expect clean mock states on every test run.

    My work around was to assign a new mock instance and test target in the test setup.

    private Mock entityMapperMock;
    private OverdraftReportMapper target;
    
    [SetUp]
    public void TestSetUp()
    {
      entityMapperMock = new Mock();
      target = new OverdraftReportMapper(entityMapperMock.Object);
    } 
    

提交回复
热议问题