DVA-C02 exam dumps

DVA-C02 practice question 273 of 399

AWS Certified Developer - Associate. Associate level, Amazon Web Services. Free question with the correct answer and a full explanation.

DVA-C02 Question 273

Single answer

A developer is building a serverless application using AWS Lambda and wants to implement unit tests to ensure the function behaves as expected. The function interacts with an Amazon DynamoDB table to retrieve data. How can the developer test the function without making actual calls to DynamoDB?

  1. A

    Use AWS X-Ray to simulate DynamoDB responses for the Lambda function.

  2. B

    Use a mock library to simulate the DynamoDB client and define expected responses.

  3. C

    Create a separate DynamoDB table for testing and point the Lambda function to this table.

  4. D

    Enable DynamoDB Streams to capture data changes and replay them during testing.

Show answer and explanation

Correct answer: B

Explanation

Unit testing aims to test the logic of the application in isolation, without dependencies on external systems like DynamoDB. Using a mock library allows developers to simulate the behavior of the DynamoDB client, ensuring the Lambda function's logic can be tested independently and efficiently.

  • A. Incorrect.

    AWS X-Ray is used for tracing and debugging distributed applications but does not simulate DynamoDB responses. It is not suitable for unit testing.

  • B. Correct.

    A mock library allows developers to simulate the DynamoDB client and control its responses, enabling unit testing without making actual network calls.

  • C. Incorrect.

    Creating a separate DynamoDB table for testing involves making real calls to the database, which is not recommended for unit testing as it is slower and less isolated.

  • D. Incorrect.

    DynamoDB Streams is used for capturing and processing data changes but does not assist in simulating responses for unit testing.

Timed practice exam

Take a DVA-C02 practice test under exam conditions

65 questions in 130 minutes, drawn from this bank, with a score report and a per-question review when you finish.

Start timed exam