What's the recommended way to automation test a Serverless application?

0

I've been struggling with this topic for ages now and haven't found a decent answer, which I'm sure means I'm likely missing something. But the question is, what?

I'm wanting to build an application that is entirely AWS Lambda based. Actually building it is easy enough, but it's the automation testing side I'm stuck on.

I can obviously write local unit tests for actual business functionality. That's easy. But it misses two major things:

First, testing the way the lambda interacts with the rest of the ecosystem. I can easily have a mock DynamoDB, a mock Cognito, or whatever, but that only tests that the lambda is calling the mock as expected. If the mock doesn't match how the service really acts then it's a huge false positive.

More importantly though is how the entire system acts. For example, that lambdas are actually able to call each other, or that the authorizer is doing the right thing for what the next lambda expects, and so on.

In the Monolith scenario, I'd run up a Docker container for each piece of infrastructure - there's likely not many of them, run up the actual monolith service in-process and then interact with it. And that works really well, is really fast and reliable, and gives fantastic confidence.

The best I can come up with for testing this kind of thing is:

  • Deploy the entire application to an ephemeral environment.
  • Run a set of E2E tests against this environment.
  • Tear down the environment.
  • Succeed/Fail based on the tests.

Using an ephemeral environment means that a failed test run doesn't bleed into the next one. But it does mean that starting the test run is slower.

But deploying an entire environment is costly - definitely in time, and possibly in money - and there's no good way to reset the environment between tests, which means there's no good way to ensure that each test is properly isolated. There's no easy way for me to call and just set a DynamoDB or a User Pool back to an empty state at the start of each test as far as I can tell. And even if there were, a Serverless application is likely to have a lot more pieces of infrastructure to reset back to a blank state, though that could be controlled by knowing which pieces need resetting for each test.

The next level would be to deploy/tear down the environment per test but that's getting a bit ridiculous at that point.

Surely though this must be a solved problem? What's the best practice way of testing that an entire serverless application is working correctly?

Cheers

asked a year ago88 views
No Answers

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions