Mock Objects - smudge202/clean-living GitHub Wiki

Usage

Mock objects are used normally in testing to simulate dependencies of an object, allowing you to test a particular method or scenario without giving the test access to real objects or systems.

Frameworks

  • Moq
  • RhinoMocks

Example

public void MyTest()
{
  //Arrange
  var mockBar = new Mock<IBar>();
  var foo = new Foo(mockBar.Object);

  //Act
  foo.DoSomething();

  //Assert
  mockBar.Verify(x => x.DoSecretThing(), Times.Exactly(1));
}

References

⚠️ **GitHub.com Fallback** ⚠️