Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

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.

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

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?

Slide 19

Slide 19 text

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