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

Testing with the AWS CDK

Momo Kornher
February 14, 2023

Testing with the AWS CDK

Talk about the state of Testing with the AWS CDK given at the German-language CDK Happy Hour Meetup.

Slides version: v0.1

Momo Kornher

February 14, 2023
Tweet

More Decks by Momo Kornher

Other Decks in Programming

Transcript

  1. TESTING WITH THE AWS CDK © 2023, Amazon Web Services,

    Inc. or its affiliates. © 2023, Amazon Web Services, Inc. or its affiliates. Testing with the AWS CDK Momo Kornher (he/him) Software Dev Engineer AWS, CDK team
  2. TESTING WITH THE AWS CDK © 2023, Amazon Web Services,

    Inc. or its affiliates. Test Pyramid E2E tests Integration tests Unit tests 2
  3. TESTING WITH THE AWS CDK © 2023, Amazon Web Services,

    Inc. or its affiliates. © 2023, Amazon Web Services, Inc. or its affiliates. End-2-End tests 3
  4. TESTING WITH THE AWS CDK © 2023, Amazon Web Services,

    Inc. or its affiliates. AWS CDK Innovation for End-to-End Tests CDK App as unit Account and Region agnostic Infrastructure next to Code 4
  5. TESTING WITH THE AWS CDK © 2023, Amazon Web Services,

    Inc. or its affiliates. © 2023, Amazon Web Services, Inc. or its affiliates. Unit tests 5
  6. TESTING WITH THE AWS CDK © 2023, Amazon Web Services,

    Inc. or its affiliates. AWS CDK Innovation for Unit Tests Template assertions Template captures Annotations assertions 6
  7. TESTING WITH THE AWS CDK © 2023, Amazon Web Services,

    Inc. or its affiliates. Unit tests: Patterns Arrange-Act-Assert or Given-When-Then Assert code path variations Test validations and features within a Construct Test helpers 7
  8. TESTING WITH THE AWS CDK © 2023, Amazon Web Services,

    Inc. or its affiliates. Unit tests: Patterns (cont.) Fine-grained assertions Assert code path variations Tests as documentation Good for testing individual Constructs 8 Not a good approach to test entire Stacks. Use Template Snapshots instead.
  9. TESTING WITH THE AWS CDK © 2023, Amazon Web Services,

    Inc. or its affiliates. Unit tests: Patterns (cont.) Template snapshots Compares the synthesized template against a stored snapshot Great to guard entire Stacks & Applications against unexpected changes 9
  10. TESTING WITH THE AWS CDK © 2023, Amazon Web Services,

    Inc. or its affiliates. © 2023, Amazon Web Services, Inc. or its affiliates. Integration tests 10
  11. TESTING WITH THE AWS CDK © 2023, Amazon Web Services,

    Inc. or its affiliates. AWS CDK Innovation for Integration Tests Constructs as reusable components 11
  12. TESTING WITH THE AWS CDK © 2023, Amazon Web Services,

    Inc. or its affiliates. Integrations between Constructs 12 API Service Construct Analytics Service Construct Compute Service Construct
  13. TESTING WITH THE AWS CDK © 2023, Amazon Web Services,

    Inc. or its affiliates. Integrations between Constructs (cont.) When Compute Service does some work Then I want Analytics Service to process logs 13 Compute Service Construct Analytics Service Construct
  14. TESTING WITH THE AWS CDK © 2023, Amazon Web Services,

    Inc. or its affiliates. © 2023, Amazon Web Services, Inc. or its affiliates. New: integ-runner 14 In developer preview
  15. TESTING WITH THE AWS CDK © 2023, Amazon Web Services,

    Inc. or its affiliates. Incoming Change Synth any changes Diff Continue only if different Deploy test cases with updates Assert functionality Accept and commit new snapshot 15 integ-runner
  16. TESTING WITH THE AWS CDK © 2023, Amazon Web Services,

    Inc. or its affiliates. Integration tests with integ-runner Assert how Constructs interact Actual deployments Simulate real behavior Contract testing Works with all languages 16 Usage: integ-runner [TEST...] [--language python] Example: integ-runner integ-compute-analytics –l python
  17. TESTING WITH THE AWS CDK © 2023, Amazon Web Services,

    Inc. or its affiliates. © 2023, Amazon Web Services, Inc. or its affiliates. What’s next? 17
  18. TESTING WITH THE AWS CDK © 2023, Amazon Web Services,

    Inc. or its affiliates. What’s next for integ-runner? Improvements Stabilize API for assertions Stabilize API for Custom Assertions i.e. calling a Custom Assertion Resource Automatically detect Dotnet, Java Framework for long-running assertions e.g. AWS CodeBuild or AWS StepFunctions Ideas for Community Constructs Contract testing e.g. integration with Pact Load testing e.g. integration with Artillery Front end testing e.g. Amazon CloudWatch Synthetics 18 Your ideas?
  19. TESTING WITH THE AWS CDK © 2023, Amazon Web Services,

    Inc. or its affiliates. © 2023, Amazon Web Services, Inc. or its affiliates. Thank you! Momo Kornher @mrgrain Find me on GitHub, Twitter & cdk.dev