AWS Step Functions are difficult to test. I found an approach to testing that helped in one particular scenario. It relies on using the same programming language for both testing and infrastructure-as-code (IaC). I hope the idea helps others tame their Step Functions into a testable submission. By Graham Allan.
Instead of testing the Step Function by executing it, I took advantage of using TypeScript for both CDK and integration tests in the same repository. I defined constants in their own file. With this simple change, I can use the DynamoDB client to execute the query in a Jest test. I run the test from my machine. I can iterate on the query without worrying about deploying or executing the Step Function. Sure, I need a real DynamoDB table, but that is rarely modified.
The article main parts will explain:
- Why are Step Functions hard to test?
- What about integration testing a Step Function?
- Adding a DynamoDB task to a Step Function
- How the shared programming language enabled better tests
Step Functions are hard to test. If that explanation does not work for you, try this: Step Functions are difficult to test in the same way stored procedures on a database server are hard to test. Having a shared programming language across IaC and tests allowed a creative way to gain confidence in author’s system, with more maintainable tests. Excellent read!
[Read More]