Consumer-driven Contract Testing

I’ve just come across the term consumer-driven contract testing and, working as a QA, was wondering a few things:

  1. what does this actually mean in laymans terms?

  2. who would generally execute this type of testing? e.g. dev or QA

  3. what tools could be used for testing this?

  4. could a specific programming language be used to test this? e.g. a framework written in C#?

@tilston1001

  1. It’s basic integration testing
  2. Both!
  3. For tools https://docs.pact.io it supports all languages.

https://cucumber.io/blog/2018/05/04/contract-testing-with-pact
https://blog.thecodewhisperer.com/permalink/integrated-tests-are-a-scam

3 Likes

A bit of software that does something specific is sometimes called a service provider. Something that needs that service is a service consumer. If a client wants data from an API the API is the provider and the client is the consumer. This communication is done under a contract - a set of specifications by which the consumer uses a provider.

CDC testing is where you write the tests from the consumer’s point of view. It has various advantages in terms of running automation, where “running automation” means to execute a series of events on a computer that may or may not have an understood purpose and “advantages” means executing those events efficiently. Not be confused with advantages for testing, which is a concern that may or may not have overlap with the former. i.e. it benefits the development project that contains the “tests” and only via that may it benefit actual testing.

It is a form of mock testing, which is testing on a partially non-real system while pretending that you’re not and assuming that it doesn’t matter.

Because the idea stems from a coding mindset from coding theory by coders usually this is written and performed by coders. Because they are technically testing (I do not here encode the quality of testing in the word “testing”) then they are also testers. Because they are part of the development of a project they are also developers like coders and testers. I don’t know what a QA is.

The only specific tool I know of is Pact. There’s no reason you can’t do it with any tool or language that interfaces with your tech stack. The tools used for CDC are also written in a language.

NB. I don’t use CDC, this is just all I know of it, I’m sure someone will correct me.

2 Likes

Thanks for the detailed response to this post @kinofrost. I’m currently running integration tests between services using pytest and python code to mock and verify interactions. Following this post I may try and experiment with Pact and see if this provides more value.

1 Like

So having spent some time investigating Contract Driven Testing and Pact in particular, I am going to be implementing it across multiple teams at my current workplace.

As part of my learning I created a dummy consumer service written in Python that runs tests against a Pact Mock which generates a Pact file. I then spun up an instance of a Pact Broker and submitted the pact file to it.

Following my experiment I am now going to be working on incorporating a Pact Broker between a two agile teams, one Java and one Python. I plan to have CI pipelines of each team automatically handling the submission and retrieval of pact files and verification results.

If anyone is interested in this let me know and I can figure out a way to share my work through some blog posts or tutorials.

1 Like

Morning Rob, I’d be very interested in having a look at this…although, admittedly, I’ve not done any programming in Python so would need to get up to speed with that

1 Like