Testing integration payloads – Testing Serverless Applications

Testing integration payloads

In the example architecture, you can test the payload sent to EventBridge by the event producer Lambda function by verifying it against a schema definition of the event.

In JavaScript, you could use a JSON schema validation library, such as Ajv:

import Ajv from “ajv”;

import { generateOrder } from “./producer”;

import OrderCreated from “../schema/[email protected]”;

test(“Should generate valid order”, () => { const actual = generateOrder();

const ajv = new Ajv();

const validate = ajv.compile(OrderCreated); expect(validate(actual)).toEqual(true);

});

Summary

Testing serverless applications is generally considered a difficult task, but this is often because it’s being viewed from the perspective of a traditional approach to testing. The reality is that there are attributes of a serverless application that can make certain testing strategies difficult to practice. So, you must reassess the way you test, as well as reconsidering your overall aims for testing and quality assurance.

Rather than battling with your serverless system under test, use its unique properties, such as its event-driven architecture and integration with managed services, to design a tailored testing strategy. Serverless testing provides maximum confidence with minimum coverage and should always be balanced with the needs of delivery, obser‐ vation, and recovery. Understand what can go wrong with serverless, but recognize that bugs are inevitable. Focus on critical paths and use static unit tests and type analysis as far as possible.

Your first step should be to use the serverless square of balance to guide the process of defining your serverless test strategy. The earlier you do this in your project the better. Once you have identified your critical paths and agreed upon the components and integrations you need to cover with tests, you can begin to get an idea of how it feels to write and run these tests and gauge the confidence they give you to deliver code into production at speed.

You must be brave enough to learn about your application’s behavior and layer in tests over time to account for emerging quirks and failures. As the serverless square of balance shows us, the key to a reliable application is leveraging observability and recovery alongside testing to maintain stability and speed. Armed with this understanding, it’s time for you to explore serverless software operations!

Leave a Reply

Your email address will not be published. Required fields are marked *