Upgrade to Pro — share decks privately, control downloads, hide ads and more …

DevFestVienna - Cloud Integration Testing Made ...

DevFestVienna - Cloud Integration Testing Made easy with LocalStack and Testcontainers

Slide deck for the first 14.10.2023 Vienna DevFest.

Anca Ghenade

October 16, 2023
Tweet

More Decks by Anca Ghenade

Other Decks in Programming

Transcript

  1. Some things cannot just easily be tested, for example plane

    sensors. Landing gear sensors to be more precise.
  2. The truth is we’ve gotten very used to being “fake”.

    • Test data → a runner that cleans a database on every test run. We get green tests with migration problems. • Selenium → a fake user, using a mouse and keyboard, over and over again. We assume it’s realistic. • Stamina → the runtime is always fresh for tests. What about subtle memory leaks? • Scaling → tests run against a single process web server. Reality: a multi-thread environment.
  3. We want to keep it as real as possible when

    we’re testing our AWS-powered applications and the interaction between various components.
  4. Environment Setup: - AWS Account: Ensure you have access to

    an AWS account for testing purposes. - Separate Test Environment: Create a separate AWS environment for integration testing to avoid affecting your production environment. - Use of AWS Services: Set up the AWS services you need for testing (databases, storage buckets, queues, Lambda functions, etc). Test Data Preparation: - Data Generation: Prepare test data to use during your integration tests. This data should mimic real-world scenarios and cover different use cases. - Data Isolation: Isolate test data from production data to prevent accidental data loss or corruption.
  5. Automate Integration Tests: - Write integration tests using test automation

    frameworks such as JUnit, TestNG, or a tool specific to your programming language or AWS services (e.g., AWS SDK for Java, AWS CDK). - Use testing libraries that support AWS services to interact with your resources programmatically (e.g., AWS SDKs, AWS Amplify, AWS CDK constructs). - Perform tests that exercise interactions between AWS services, such as Lambda functions invoking other services, S3 bucket operations, or SQS queue processing. Test Scenarios: - Test various scenarios, including both positive and negative cases. Ensure that your tests cover different service interactions, error handling, and edge cases.
  6. Service Isolation: - Isolate AWS services as needed to ensure

    that your tests do not interfere with each other or the production environment. This can involve using separate AWS accounts or resource tagging. Testing AWS Lambda Functions: - Test AWS Lambda functions locally using a local development environment or tools like the AWS SAM CLI. - Automate the deployment and invocation of Lambda functions during testing.
  7. Security Testing: - Include security testing in your integration tests

    to identify vulnerabilities and ensure that AWS security configurations are correct. - Test IAM roles, security groups, and network configurations. Cleanup and Resource Management: - Implement resource cleanup procedures to ensure that resources created during testing are properly disposed of to avoid unnecessary costs and resource leakage. Continuous Integration (CI): - Integrate integration tests into your CI/CD pipeline to ensure that tests are executed automatically whenever code changes are pushed.
  8. Documentation and Reporting: - Document test scenarios, results, and any

    issues encountered during integration testing. - Use reporting and visualization tools to present test results in a clear and actionable format. Regression Testing: Periodically rerun integration tests to catch regressions as you make changes or updates to your AWS infrastructure and application code.
  9. Pros: • Confidence → Passing tests = it works •

    Fewer tests = less effort Cons: • Tests can’t provide many design cues • Slow feedback • High coverage is infeasible
  10. Pros: • Every object is exercised by many tests →

    high regression value • Practical tests without deep knowledge of your mocks Cons: • One change and everything needs to be adjusted • End-to-end tests become redundant • Limited feedback/knowledge about interaction if you do TDD
  11. How much of your system you can test Cloud emulation

    Staging environments Real AWS Mocking So how much reality can we have in cloud application testing? 3 4 Service emulation 2 1
  12. And how can we bring the ease and speed of

    unit tests into our integration tests?
  13. What is LocalStack and how can it help you? A

    fully functional local cloud stack that was born out of these exact concerns.
  14. • Enables a highly efficient dev & test loop for

    cloud apps • Ships as a Docker image, easy to install and start up • Support for 90-ish services (and growing): ◦ compute (Lambda, ECS, EKS) ◦ various databases (DynamoDB, RDS) ◦ messaging (SQS, Kinesis, MSK) ◦ some sophisticated/exotic APIs (Athena, Glue) • CI integrations & advanced collaboration features ◦ redefining the way cloud apps are developed across the lifecycle!
  15. 1/2

  16. 2/2

  17. Use a waiter to make sure your Lambdas are in

    state ACTIVE and not just created.
  18. Use this nifty configuration to scan the LocalStack logs and

    make sure your instance is in the right state before the tests are allowed to start:
  19. testing I have no doubt that you would be bored

    senseless by therapy, the same way I'm bored when I brush my teeth and wipe my ass. Because the thing about repairing, maintaining, and cleaning is it's not an adventure. There's no way to do it so wrong you might die. It's just work. And the bottom line is, some people are okay going to work, and some people, well, some people would rather die.
  20. Just FYI - Top 3 podium - Game of correctness

    and agility - You can play as many times as you want
  21. How much of your system you can test Cloud emulation

    Staging environments Real AWS Mocking 3 4 Service emulation 2 1