Topic 1 Question 129
A developer is creating an AWS Lambda function. The Lambda function will consume messages from an Amazon Simple Queue Service (Amazon SQS) queue. The developer wants to integrate unit testing as part of the function's continuous integration and continuous delivery (CI/CD) process.
How can the developer unit test the function?
Create an AWS CloudFormation template that creates an SQS queue and deploys the Lambda function. Create a stack from the template during the CI/CD process. Invoke the deployed function. Verify the output.
Create an SQS event for tests. Use a test that consumes messages from the SQS queue during the function's Cl/CD process.
Create an SQS queue for tests. Use this SQS queue in the application's unit test. Run the unit tests during the CI/CD process.
Use the aws lambda invoke command with a test event during the CIICD process.
ユーザの投票
コメント(13)
- 正解だと思う選択肢: C
Unit testing is a type of testing that verifies the correctness of individual units of source code, typically functions or methods. When unit testing a Lambda function that interacts with Amazon SQS, you can create a separate test SQS queue that the Lambda function interacts with during testing. You would then validate the behavior of the function based on its interactions with the test queue. This approach isolates the function's behavior from the rest of the system, which is a key principle of unit testing.
Option A is incorrect because AWS CloudFormation is typically used for infrastructure deployment, not for unit testing.
Option B is incorrect because it does not actually test the function; it only creates an event.
Option D is incorrect because the 'aws lambda invoke' command is used to manually trigger a Lambda function, but doesn't necessarily facilitate testing the function's behavior when consuming messages from an SQS queue.
👍 11gagol142023/06/19 - 正解だと思う選択肢: D
D is correct here. Both B and C are integration tests as they are using an actual SQS queue in the tests and not mocking it out.
👍 7redfivedog2023/07/26 - 正解だと思う選択肢: B
Explanation:
Option B involves simulating the SQS event trigger for testing purposes. This is a common practice in AWS Lambda unit testing. Here's how it works:
SQS Event for Tests: In your unit test code, you can create an SQS event object that simulates the event structure that Lambda receives when an SQS message is consumed. This event object will contain the necessary information, such as the message content, message attributes, etc.
Testing Logic: You can then pass this event object to your Lambda function's handler function as if it were an actual SQS event. This allows you to test your Lambda function's logic as it would work in response to an SQS message.
Mocking Dependencies: During unit testing, you might want to mock any AWS service calls, such as SQS, to isolate your Lambda function's logic from external services.
👍 6love7772023/08/23
シャッフルモード