In the present day, I’m excited to announce enhanced native testing capabilities for AWS Step Capabilities by the TestState API, our testing API.
These enhancements can be found by the API, so you’ll be able to construct automated check suites that validate your workflow definitions domestically in your improvement machines, check error dealing with patterns, information transformations, and mock service integrations utilizing your most popular testing frameworks. This launch introduces an API-based strategy for native unit testing, offering programmatic entry to complete testing capabilities with out deploying to Amazon Net Providers (AWS).
There are three key capabilities launched on this enhanced TestState API:
-
Mocking help – Mock state outputs and errors with out invoking downstream providers, enabling true unit testing of state machine logic. TestState validates mocked responses towards AWS API fashions with three validation modes: STRICT (that is the default and validates all required fields), PRESENT (validates subject sorts and names), and NONE (no validation), offering high-fidelity testing.
-
Help for all state sorts – All state sorts, together with superior states akin to Map states (inline and distributed), Parallel states, activity-based Process states, .sync service integration patterns, and .waitForTaskToken service integration patterns, can now be examined. This implies you should utilize TestState API throughout your total workflow definition and write unit exams to confirm management circulation logic, together with state transitions, error dealing with, and information transformations.
-
Testing particular person states – Check particular states inside a full state machine definition utilizing the brand new stateName parameter. You may present the entire state machine definition one time and check every state individually by identify. You may management execution context to check particular retry makes an attempt, Map iteration positions, and error eventualities.
Getting began with enhanced TestState
Let me stroll you thru these new capabilities in enhanced TestState.
State of affairs 1: Mock profitable outcomes
The primary functionality is mocking help, which you should utilize to check your workflow logic with out invoking precise AWS providers and even exterior HTTP requests. You may both mock service responses for quick unit testing or check with precise AWS providers for integration testing. When utilizing mocked responses, you don’t want AWS Id and Entry Administration (IAM) permissions.
Right here’s learn how to mock a profitable AWS Lambda perform response:
aws stepfunctions test-state --region us-east-1
--definition '{
"Kind": "Process",
"Useful resource": "arn:aws:states:::lambda:invoke",
"Parameters": {"FunctionName": "process-order"},
"Finish": true
}'
--mock '{"outcome":"{"orderId":"12345","standing":"processed"}"}'
--inspection-level DEBUG
This command exams a Lambda invocation state with out truly calling the perform. TestState validates your mock response towards the Lambda service API mannequin so your check information matches what the actual service would return.
The response reveals the profitable execution with detailed inspection information (when utilizing DEBUG inspection degree):
{
"output": "{"orderId":"12345","standing":"processed"}",
"inspectionData": {
"enter": "{}",
"afterInputPath": "{}",
"afterParameters": "{"FunctionName":"process-order"}",
"outcome": "{"orderId":"12345","standing":"processed"}",
"afterResultSelector": "{"orderId":"12345","standing":"processed"}",
"afterResultPath": "{"orderId":"12345","standing":"processed"}"
},
"standing": "SUCCEEDED"
}
If you specify a mock response, TestState validates it towards the AWS service’s API mannequin so your mocked information conforms to the anticipated schema, sustaining high-fidelity testing with out requiring precise AWS service calls.
State of affairs 2: Mock error situations
You can even mock error situations to check your error dealing with logic:
aws stepfunctions test-state --region us-east-1
--definition '{
"Kind": "Process",
"Useful resource": "arn:aws:states:::lambda:invoke",
"Parameters": {"FunctionName": "process-order"},
"Finish": true
}'
--mock '{"errorOutput":{"error":"Lambda.ServiceException","trigger":"Operate failed"}}'
--inspection-level DEBUG
This simulates a Lambda service exception so you’ll be able to confirm how your state machine handles failures with out triggering precise errors in your AWS setting.
The response reveals the failed execution with error particulars:
{
"error": "Lambda.ServiceException",
"trigger": "Operate failed",
"inspectionData": {
"enter": "{}",
"afterInputPath": "{}",
"afterParameters": "{"FunctionName":"process-order"}"
},
"standing": "FAILED"
}
State of affairs 3: Check Map states
The second functionality provides help for beforehand unsupported state sorts. Right here’s learn how to check a Distributed Map state:
aws stepfunctions test-state --region us-east-1
--definition '{
"Kind": "Map",
"ItemProcessor": {
"ProcessorConfig": {"Mode": "DISTRIBUTED", "ExecutionType": "STANDARD"},
"StartAt": "ProcessItem",
"States": {
"ProcessItem": {
"Kind": "Process",
"Useful resource": "arn:aws:states:::lambda:invoke",
"Parameters": {"FunctionName": "process-item"},
"Finish": true
}
}
},
"Finish": true
}'
--input '[{"itemId":1},{"itemId":2}]'
--mock '{"outcome":"[{"itemId":1,"status":"processed"},{"itemId":2,"status":"processed"}]"}'
--inspection-level DEBUG
The mock outcome represents the entire output from processing a number of gadgets. On this case, the mocked array should match the anticipated Map state output format.
The response reveals profitable processing of the array enter:
{
"output": "[{"itemId":1,"status":"processed"},{"itemId":2,"status":"processed"}]",
"inspectionData": {
"enter": "[{"itemId":1},{"itemId":2}]",
"afterInputPath": "[{"itemId":1},{"itemId":2}]",
"afterResultSelector": "[{"itemId":1,"status":"processed"},{"itemId":2,"status":"processed"}]",
"afterResultPath": "[{"itemId":1,"status":"processed"},{"itemId":2,"status":"processed"}]"
},
"standing": "SUCCEEDED"
}
State of affairs 4: Check Parallel states
Equally, you’ll be able to check Parallel states that execute a number of branches concurrently:
aws stepfunctions test-state --region us-east-1
--definition '{
"Kind": "Parallel",
"Branches": [
{"StartAt": "Branch1", "States": {"Branch1": {"Type": "Pass", "End": true}}},
{"StartAt": "Branch2", "States": {"Branch2": {"Type": "Pass", "End": true}}}
],
"Finish": true
}'
--mock '{"outcome":"[{"branch1":"data1"},{"branch2":"data2"}]"}'
--inspection-level DEBUG
The mock outcome should be an array with one ingredient per department. Through the use of TestState, your mock information construction matches what an actual Parallel state execution would produce.
The response reveals the parallel execution outcomes:
{
"output": "[{"branch1":"data1"},{"branch2":"data2"}]",
"inspectionData": {
"enter": "{}",
"afterResultSelector": "[{"branch1":"data1"},{"branch2":"data2"}]",
"afterResultPath": "[{"branch1":"data1"},{"branch2":"data2"}]"
},
"standing": "SUCCEEDED"
}
State of affairs 5: Check particular person states inside full workflows
You may check particular states inside a full state machine definition utilizing the stateName parameter. Right here’s an instance testing a single state, although you’ll usually present your full workflow definition and specify which state to check:
aws stepfunctions test-state --region us-east-1
--definition '{
"Kind": "Process",
"Useful resource": "arn:aws:states:::lambda:invoke",
"Parameters": {"FunctionName": "validate-order"},
"Finish": true
}'
--input '{"orderId":"12345","quantity":99.99}'
--mock '{"outcome":"{"orderId":"12345","validated":true}"}'
--inspection-level DEBUG
This exams a Lambda invocation state with particular enter information, displaying how TestState processes the enter and transforms it by the state execution.
The response reveals detailed enter processing and validation:
{
"output": "{"orderId":"12345","validated":true}",
"inspectionData": {
"enter": "{"orderId":"12345","quantity":99.99}",
"afterInputPath": "{"orderId":"12345","quantity":99.99}",
"afterParameters": "{"FunctionName":"validate-order"}",
"outcome": "{"orderId":"12345","validated":true}",
"afterResultSelector": "{"orderId":"12345","validated":true}",
"afterResultPath": "{"orderId":"12345","validated":true}"
},
"standing": "SUCCEEDED"
}
These enhancements carry the acquainted native improvement expertise to Step Capabilities workflows, serving to me to get immediate suggestions on adjustments earlier than deploying to my AWS account. I can write automated check suites to validate all Step Capabilities options with the identical reliability as cloud execution, offering confidence that my workflows will work as anticipated when deployed.
Issues to know
Listed below are key factors to notice:
- Availability – Enhanced TestState capabilities can be found in all AWS Areas the place Step Capabilities is supported.
- Pricing – TestState API calls are included with AWS Step Capabilities at no extra cost.
- Framework compatibility – TestState works with any testing framework that may make HTTP requests, together with Jest, pytest, JUnit, and others. You may write check suites that validate your workflows routinely in your steady integration and steady supply (CI/CD) pipeline earlier than deployment.
- Characteristic help – Enhanced TestState helps all Step Capabilities options together with Distributed Map, Parallel states, error dealing with, and JSONata expressions.
- Documentation – For detailed choices for various configurations, seek advice from the TestState documentation and API reference for the up to date request and response mannequin.
Get began at the moment with enhanced native testing by integrating TestState into your improvement workflow.
Pleased constructing!
— Donnie


