DEV Community

Cover image for ServerlessSpy—Gain Insight into the Cloud and Write Serverless Tests with Ease 
Marko - ServerlessLife.com
Marko - ServerlessLife.com

Posted on • Originally published at serverlesslife.com

ServerlessSpy—Gain Insight into the Cloud and Write Serverless Tests with Ease 

ServerlessSpy is a CDK-based library for writing integration tests on AWS serverless, and it comes with a web console to monitor events in real time.

Writing tests for serverless is challenging. Unit tests often do not provide much value because all services need to be mocked. Integration tests that run on the real cloud infrastructure are the preferred way to test such a system. But integration tests are hard to write, and they are slow to execute. A serverless system is usually built as an asynchronous event-driven system. That means that you put an event in on one side, and after some time, you get some output on the other side. You do not know when, so you have to keep checking. That is slow. At the same time, no other tests can usually run because they will mess up your data. The last issue is that you often have to save the message in some storage just for the integration test to be able to inspect the message.

That's why I created a ServerlessSpy, which resolves the problems mentioned above. It provides a CDK construct that creates infrastructure to intercept events in Lambda, SNS, SQS, EventBridge, DynamoDB, and S3, and sends it to a testing library via API Gateway WebSocket. The testing library subscribes to events so that tests can be executed fast without checking/retrying if the process has finished. You do not have to build additional infrastructure to temporarily store the events. Tests can also run in parallel because you can filter events to receive only the ones meant for your test case.

ServerlessSpy can be used for more than writing integration tests. A special web console can receive events from WebSocket. The console enables you to inspect events in real time and see what is happening in the cloud. Some say it is even more useful than the part for writing integration tests.

Writing integration tests for #serverless used to be a tedious job. #ServerlessSpy with the magic of #CDK and #TypeScript makes writing integration tests fast and pleasant.

Key benefits:

  • Easy to write tests that are strongly typed thanks to TypeScript.
  • Tests are executed much FASTER. No need to write tests in a way to periodically check if the process has finished because all events are pushed to the testing library.
  • Tests can run in parallel if you use conditions and filter events specific to your test. This drastically reduces the execution time of the CI/CD process.
  • Web console enables you to see all events in real time. Debugging has never been easier. Search for events is also supported (with regular expression).

Continue reading on www.serverlesslife.com...

Top comments (0)