This repo shows how to write contract tests in C# with Xunit where the contract is in one project and the derived test is in another. The contracts help to ensure that the business logic of our test fixtures is in sync with the logic of the production implementation.
Our application only knows about the IBooks interface. In our unit tests we can pass in a fake implementation that does not write to the database: InMemoryBooks. This keeps the unit tests fast, makes the clean up very simple and provides an easy way for test isolation. But there is the danger that the fake implementation becomes out-of-sync with the actual production implementation MongoBooks.
That’s where contract tests come in. The BooksContract is an abstract class
and implemented by two different tests that supply the two different IBooks implementations.