Testing and test automation: DVA-C03 study notes and practice questions
What to know about Testing and test automation for the DVA-C03 exam, from the Testing and Deployment domain (22% of the exam guide), then 3 free questions to test it. Part of the DVA-C03 study guide.
These questions ask where a test should run, what it should use in place of real dependencies, and which tool produces the test data.
SAM local and remote
sam local invoke runs one function in a Docker container on your machine, with an event you supply as JSON. Use it for fast checks that need no deployed resources.
sam local start-api runs the API routes locally so you can call them with curl or a browser. It does not call your real API Gateway.
sam remote invoke runs a function that is already deployed in an AWS account. It tests the real IAM role, environment and integrations.
sam sync pushes code changes to a development stack quickly. It is for development, not for releases.
CDK and CloudFormation tests
Template and construct tests check the synthesized CloudFormation output, for example that a bucket has encryption turned on. They run without deploying.
cfn-lint and policy checks catch template errors before a deployment.
Use these tests to prove infrastructure rules hold. Use sam local or integration tests to prove code runs.
Mock APIs
An API Gateway mock integration returns a response from the method itself, without calling a backend. Use it to let a front-end team build against a contract before the backend exists.
Mock integrations are for testing and early development. They do not call any other service.
Test events
A Lambda test event is a JSON payload that matches the trigger’s shape. An S3 event carries the bucket name and object key, and an API Gateway event carries the path, method and body.
The Lambda console can save test events and share them with other people in the account, so a team tests with the same input.
Amplify branch environments
Amplify Hosting connects to a Git branch. Each connected branch gets its own build, its own URL and its own backend environment, so a develop branch can be a test site next to main production.
Use branch environments when the question asks for an isolated, per-branch test environment that a developer can reach without a separate pipeline.
AI tools for testing
Amazon Q Developer’s IDE plugins closed to new customers on May 15, 2026. Kiro is the IDE that DVA-C03 names for AI-assisted development, including generating tests from a spec or from existing code.
AI tools can generate unit tests, analyze results and automate regression runs. Review generated tests, because they can assert the wrong behavior.
How to choose
Scenario wording
Answer
Test one function locally with a sample S3 event
sam local invoke with an event file
Test a function with its real IAM role, already deployed
sam remote invoke
Let a frontend build before the backend exists
API Gateway mock integration
Check that a template enables encryption, without deploying
Template or CDK assertion tests
Test each Amplify branch separately
Amplify branch environments
Common traps
Using sam local to test IAM permissions. It uses your credentials, not the function’s role.
Calling real services in a unit test when a mock or stub is what the question asks for.
A developer has an AWS SAM application with a function that runs whenever an object is uploaded to an Amazon S3 bucket.
The function is one step in the team's order pipeline, and its handler reads the bucket and key from each event. Before deploying anything, the developer wants to run the function on a laptop with a realistic S3 upload event.
Which approach should the developer use?
Choose one answer.
AA. Run sam deploy to a test stack, then upload an object to the bucket and check the function's CloudWatch logs.
BB. sam local start-api runs a local HTTP endpoint for API Gateway-style events, so the developer can send requests to it.
CC. Run sam local generate-event s3 put to create a sample event, then sam local invoke with that event file.
DD. Invoke the function from the Lambda console's test feature, pointing it at a local copy of the code and a sample event.
Show the answer and explanation
Answer: C
A. Wrong: A test stack would work, but it deploys to AWS and uses cloud resources, which the developer wants to avoid before deploying. It does not test the function on the laptop.
B. Wrong: sam local start-api runs an HTTP endpoint for API Gateway-style events. An S3 notification is not an HTTP request, so the function would not receive a realistic S3 event.
D. Wrong: The Lambda console runs functions in AWS, not on a laptop, and it cannot run local code. It does not meet the need to test locally before deploying.
Explanation
The SAM CLI runs a function locally in a container. sam local generate-event creates a realistic sample event for services such as S3, and passing that event to sam local invoke tests the handler with a realistic payload. Local runs do not check IAM permissions, so the function should also be tested in AWS.
A partner API in Amazon API Gateway is a REST API with two stages, dev and prod, and one integration definition shared by both.
The backing Lambda function has aliases named dev and prod that point to different versions. Each stage must invoke only its own alias, and the team wants to avoid copies of the API definition.
Which TWO steps are required? (Choose two.)
Choose two answers.
AA. Add a resource-based permission on each alias that lets apigateway.amazonaws.com invoke it, using the alias as the qualifier.
BB. Create a separate REST API for each stage, each with its own hard-coded alias and deployment in the integration.
CC. Point every integration at $LATEST, which needs no permission and no stage-specific setup.
DD. Use ${stageVariables.lambdaAlias} as the alias in the function ARN, with lambdaAlias set to dev or prod per stage.
EE. Enable X-Ray tracing on the prod stage so that API Gateway can resolve the alias name.
B. Wrong: This can work, but it breaks the requirement to keep one API definition. Every change must then be made in each copy, which the team wants to avoid.
C. Wrong: $LATEST is the unpublished, editable version, so both stages would run the same changing code. This removes the per-stage aliases that keep dev and prod on separate versions.
E. Wrong: X-Ray tracing records requests for debugging. It does not change which Lambda alias an integration calls, so it is unrelated to alias routing.
Explanation
Stage variables let one REST API definition call a different Lambda function or alias for each stage, but they do not grant permission. Each alias that API Gateway calls needs its own resource-based permission. Copying the API or pointing at $LATEST each breaks one of the stated requirements.
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 →