《测试无服务器事件驱动应用程序的有效策略 [重复].pdf》由会员分享,可在线阅读,更多相关《测试无服务器事件驱动应用程序的有效策略 [重复].pdf(15页珍藏版)》请在三个皮匠报告上搜索。
1、 2025,Amazon Web Services,Inc.or its affiliates.All rights reserved.2025,Amazon Web Services,Inc.or its affiliates.All rights reserved.C N S 3 1 6-REffective strategies for testing serverless event-driven applicationsRohan Mehta(he/him)Worldwide Serverless Specialist Solutions ArchitectBrian Krygsma
2、n(he/him)Senior Solutions Architect 2025,Amazon Web Services,Inc.or its affiliates.All rights reserved.What developers are used toDeveloper workstation 2025,Amazon Web Services,Inc.or its affiliates.All rights reserved.Cloud-native applications are differentAWS Cloud?Developer workstation 2025,Amazo
3、n Web Services,Inc.or its affiliates.All rights reserved.Should you still create automated tests?Especially when you:will deploy to a production environmentexpect to evolve,grow,and maintain your application over timerequire quality,reliability,and development speedYes!2025,Amazon Web Services,Inc.o
4、r its affiliates.All rights reserved.Areas of focus for todayUnit testingIntegration testingAsynchronous/event-driven unless you have better ones 2025,Amazon Web Services,Inc.or its affiliates.All rights reserved.2025,Amazon Web Services,Inc.or its affiliates.All rights reserved.Unit testing 2025,Am
5、azon Web Services,Inc.or its affiliates.All rights reserved.Example code for mockingimport boto3from moto import mock_s3mock_s3def test_lambda_handler(apigw_event:dict)-None:#set up test bucket s3_client=boto3.client(s3)test_bucket_names=test_bucket1,test_bucket2 for test_bucket_name in test_bucket_
6、names:s3_client.create_bucket(Bucket=test_bucket_name)#call lambda function handler with synthetic event test_response=app.lambda_handler(apigw_event,)test_response_data=test_responsebody.split(|)#evaluate response assert test_bucket_names0 in test_response_data assert test_bucke