DVA-C02 exam dumps

DVA-C02 practice question 49 of 399

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

DVA-C02 Question 49

Select 3

You are developing a serverless application using AWS Lambda and want to implement unit testing for your handler function. The function interacts with DynamoDB to perform CRUD operations. Which of the following practices should you follow to ensure effective unit testing?

  1. A

    Mock the DynamoDB client to simulate responses for your unit tests.

  2. B

    Use a live DynamoDB table to test the actual CRUD operations during unit testing.

  3. C

    Write separate tests for each logical branch of your handler function.

  4. D

    Include integration tests as part of your unit testing suite.

  5. E

    Ensure your unit tests are independent of AWS services and external dependencies.

Show answer and explanation

Correct answers: A, C, E

Explanation

Unit testing focuses on testing the function in isolation from external dependencies. In the case of an AWS Lambda function interacting with DynamoDB, mocking the DynamoDB client ensures the tests do not rely on actual AWS services. Writing tests for each logical branch ensures code coverage, while ensuring independence from external dependencies aligns with the principle of unit testing. Practices like using live AWS resources or including integration tests violate the scope of unit testing.

  • A. Correct.

    Correct. Mocking the DynamoDB client allows you to simulate responses without relying on an actual DynamoDB table, which is aligned with the purpose of unit testing (testing code in isolation).

  • B. Incorrect.

    Incorrect. Using a live DynamoDB table introduces external dependencies, making the tests integration tests rather than unit tests. Unit tests should focus on testing code in isolation.

  • C. Correct.

    Correct. Writing separate tests for each logical branch ensures that all parts of your function's logic are covered and tested individually.

  • D. Incorrect.

    Incorrect. Integration tests are separate from unit tests. While important, they should not be included in a unit testing suite because unit tests specifically test isolated components.

  • E. Correct.

    Correct. Unit tests should not depend on external services like AWS. Using mocks or stubs ensures the tests are independent and can run in any environment.

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