Unit Tests - Serverless Architectures with AWS Lambda

Unit Tests

With what we’ve said earlier in mind, we recommend that you unit test your Lambda function code thoroughly, focusing mostly on the business logic outside your handler function. You should also unit test your ability to parse sample/mock objects for the event sources of your function. However, the bulk of your logic and tests should occur with mocked objects and functions that you have full control over within your code base. If you feel that there are important things inside your handler function that need to be unit tested, it can be a sign you should encapsulate and externalize the logic in your handler function further. Also, to supplement the unit tests you’ve written, you should create local test automation using AWS SAM Local that can serve as local end-to-end testing of your function code (note that this isn’t a replacement for unit testing).