A team runs an order workflow in AWS Step Functions. One Task state calls a payment Lambda function, with a Retry for Lambda.ServiceException and a Catch that sends Payment.Declined errors to a HandleDecline state.
The team wants unit tests in its CI pipeline that prove each error goes to the right handler. The tests must not call the real payment function or deploy a state machine on each run.
Which approach meets these requirements?
Choose one answer.
AA. Deploy the state machine to a test account on each pipeline run, start executions with inputs that make the payment function fail, and check the execution history.
BB. Run the payment function with sam local invoke and an event that makes it throw Payment.Declined, and check the error the function returns.
CC. Turn on AWS X-Ray tracing for the state machine, and check in production traces which state ran after each failed payment step.
DD. Call the TestState API with the state's definition and a mocked errorOutput for each error, then assert on the status and nextState fields it returns.
Show the answer and explanation
Answer: D
A. Wrong: This tests the real path, but it deploys a state machine and calls the real function on every run. Both are ruled out by the requirements.
B. Wrong: This tests the function's own code, not the state's Retry and Catch rules. It cannot show which state the workflow moves to after the error.
C. Wrong: Traces show what happened in real executions after the fact. They are not repeatable unit tests in the pipeline, and they depend on real payment failures.
D. Right: Correct. TestState runs one state without creating or updating a state machine, and a mock replaces the Lambda call. The response shows whether the error was retried or caught and which state comes next, and no execution role is needed when a mock is used. Learn more: Testing state machines with TestState API (opens in a new tab)
Explanation
The Step Functions TestState API runs a single state definition without deploying a state machine. With a mocked result or errorOutput, it skips the real service call, and its response reports the status, such as RETRIABLE or CAUGHT_ERROR, and the nextState. That makes Retry and Catch logic testable in CI without calling the payment function.
Want more on Testing and test automation? The 5 full-length practice sets have 12 more Testing and test automation questions, 390 in all, none of them in the free exam. One payment of $14.99, no subscription. See the practice sets →