Home > front end >  How to perform integration testing on AWS Step Function
How to perform integration testing on AWS Step Function

Time:12-17

I have a REST API in API Gateway with lambda proxy integration. The Lambda will invoke a Step Function workflow asynchronously and will return an ID in the payload. These AWS resources are deployed and managed by AWS CDK.

My question is, is there a proper way to perform integration test? There are two approaches I have in mind:

  1. Call the REST API endpoint, and make assertions on side effects. But since the workflow is executed asynchronously, the test needs to continuously poll until side effects become visible.
  2. According to this blog https://www.10printiamcool.com/step-function-integration-testing-with-cdk, it seems like we can use CDK to deploy a test stack with mocking the dependent resources (e.g Lambda). But this sounds more of like unit test.

I am not sure if there are any better options. Any thoughts?

CodePudding user response:

I understand you want integration tests on your Step Function in the context of a serverless CDK app. Your pass criteria for the Step Function include certain async backend side-effects in addition to a 200 API response.

Given that context, here are some ideas on two related topics:

How to engineer the Step Function tests

How about testing your Step Function's integration ... with another Step Function? A TestSfn would map through test cases, in turn calling the API with various inputs in one Task and checking for expected side-effects in another Task. After all, Step Functions are really good at orchestrating step-wise, async workflows in parallel, which is what your use case demands. The tests pass if TestSfn succeeds. The execution history console and logs give great visibility to diagnose test failures.

Test environments

The serverless CDK setup makes it easy, fast and cheap to adopt the best practice multi-account strategy and spin-up and spin-down full, non-prod deployments of your entire app to test on.

You can perform ad hoc testing in a day-to-day dev environment and cdk destroy at the end of the day. And/or build CDK CI/CD pipeline that deploys to your prod environment on push to main if tests pass: [pull from github] -> [deploy stacks to TEST account] -> [seed test data] -> [run tests] -> [destroy TEST stacks] -> [deploy stacks to PROD acccount].

  • Related