简体   繁体   English

使用 Python 的 AWS Lambda 集成测试的代码覆盖率报告

[英]Code Coverage Report for AWS Lambda Integration test using Python

I have written integration tests for lambdas that hit the dev site (in AWS).我已经为到达开发站点(在 AWS 中)的 lambdas 编写了集成测试。 The tests are working fine.测试工作正常。 Tests are written in a separate project that uses a request object to hit the endpoint to validate the result.测试是在一个单独的项目中编写的,该项目使用请求 object 来访问端点以验证结果。

Currently, I am running all the tests from my local.目前,我正在本地运行所有测试。 Lambdas are deployed using a separate Jenkins job. Lambda 使用单独的 Jenkins 作业部署。

However, I need to generate a code coverage report for these tests.但是,我需要为这些测试生成代码覆盖率报告。 I am not sure how I can generate the code coverage report as I am directly hitting the dev URL from my local.我不确定如何生成代码覆盖率报告,因为我直接从本地访问 dev URL。 I am using Python 3.8.我正在使用 Python 3.8。

All the lambdas have lambda layers which provide a database connection and some other common business logic.所有的 lambda 都有 lambda 层,它们提供数据库连接和一些其他常见的业务逻辑。

Thanks in advance.提前致谢。

Code coverage is probably not the right metric for integration tests.代码覆盖率可能不是集成测试的正确指标。 As far as I can tell you use integration tests to test your requirements/use cases/user stories.据我所知,您可以使用集成测试来测试您的需求/用例/用户故事。

Imagine you have an application with a shopping cart feature.想象一下,您有一个具有购物车功能的应用程序。 A user has 10 items in that shopping cart and now deletes one of those items.用户在该购物车中有 10 件商品,现在删除其中一件商品。 Your integration test would make sure that after this operation only (the correct) 9 items are left in the shopping cart.您的集成测试将确保在此操作之后,购物车中只剩下(正确的)9 件商品。

For this kind of testing it is not relevant which/how much code was run.对于这种测试,运行哪个/多少代码无关紧要。 It is more like a black box test.它更像是一个黑盒测试。 You want to know that for a given "action" the correct "state" is created.您想知道对于给定的“动作”是否创建了正确的“状态”。

Code coverage is usually something you use with unit tests.代码覆盖率通常是您在单元测试中使用的东西。 For integration tests I think you want to know how many of your requirements/use cases/user stories are covered.对于集成测试,我认为您想知道涵盖了多少需求/用例/用户故事。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM