Serverless Contract Testing

A different approach to serverless integration testing

Kinesis contract testing

The Serverless Challenge

Serverless architectures introduce new challenges to testing - more components, multiple languages and frameworks - as well as vendor-specific products such as Lambda and Kinesis.

Teams embarking on a serverless journey often have to navigate vendor lock-in, an explosion in the number of integration points and styles, and testing services that don't run on their laptops.

More integrations, more asynchronous services

The modern microservice is more like an iceberg, with a small "API" facing the outside world and a complex network of components feeding and servicing a broader system.

Application developers have recognised that asynchronous communication is a resilient backbone to this architecture, however in this mode integration failures can be particularly tricky to resolve.

Furthermore, spinning up full end-to-end environments to do integration testing across bounded contexts (e.g. teams) is complicated, expensive and error prone.

A different approach

A key insight is that each component in the system maintains separate contracts with the other components in which it integrates.

Using a contract testing tool such as Pact, developers and testers can write simple, isolated unit tests for each integration in their application and generate API contracts (independent of language / framework) that are guaranteed to be up-to-date with their code, ensuring all dependencies are always compatible.

With Pactflow's integration tools, you can reduce this complexity by allowing you to focus on the messages exchanged between the system and get feedback at build time on system compatibility.

Example AWS Services

Lambda functions for application processing

Document Stores such as DynamoDB for structured object storage, or S3 when used in Data Lake or "hipster batch" architecture

Message queues such as Kinesis, SNS, IoT Broker and Kafka.

Getting Started resources

Introduction to contract testing

Contract testing is an approach that captures the interactions between two services and serialises them into a contract, which can then be used to verify that both parties adhere to it.

The following article is an introduction to Pact and contract tetsing:

Serverless and Asynchronous Testing with Pact

Intermediate level article on how you can apply contract-testing to serverless architectures

How can you use contract testing to scale teams?