0

What is the best way to perform a test of contracts, when the endpoint of the provider performs a persistence of data?

For example, the registration of a client. Should I consider the rollback of the data in the pipeline?

2 Answers2

0

Considering that Client Driven Contract tests are not (usually) supposed to be functional tests, I mock everything bellow my provider Resource that handles the rest call. Therefore, no data is persisted and it also simplifies the test a lot, because you remove any dependencies on external components, including databases.

For instance, if your ClientResource (or ClientController, depending on your name pattern) calls a ClientRepository, the ClientRepository would be mocked.

Fabricio Lemos
  • 2,905
  • 2
  • 31
  • 31
0

I make the decision based the the tradeoffs of mocking/not mocking for each particular codebase. I've worked on microservices where it was very easy to just rollback the transaction, so I used the real database for those tests. I've also worked on systems where it made more sense to mock the repository, as suggested by Fabricio. I always mock downstream service dependencies.

Beth Skurrie
  • 1,333
  • 7
  • 8