简体   繁体   English

如何为 aws lambda 处理程序 function (Python) 编写单元测试

[英]How to write unit test for aws lambda handler function (Python)

Everyone每个人

I have a function which is the handler for aws lambdafunction.我有一个 function,它是 aws lambdafunction 的处理程序。

def data_list(event, data_subject):
    dynamodb = boto3.resource("dynamodb")
    table = dynamodb.Table("TestTable")
    print("DATA_LIST")

    def get_col_name(data_subject):
        if data_subject == "X":
            return 'something'
        elif data_subject == "y":
            return 'some other things'
        elif data_subject == "c":
            return 'really'

    def another_function(var):
        pass

I have multiple function under data_list function how can we write unittest cases for each individual function which is under data_list function I have multiple function under data_list function how can we write unittest cases for each individual function which is under data_list function

Don't.不。

Instead move them out from the lambda handler function so that you can test them entirely separately.而是将它们从 lambda 处理程序 function 中移出,以便您可以完全单独测试它们。

Then make the lambda handler function it's self so small and simple that you barely need to test it, and can handle testing it with system tests.然后让 lambda 处理程序 function 它本身如此小巧简单,您几乎不需要对其进行测试,并且可以通过系统测试对其进行测试。

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

相关问题 单元测试模拟 AWS Lambda 函数,Python - Unit Test mocking AWS Lambda Function, Python AWS Lambda函数处理程序python - aws lambda function handler python Python AWS Lambda 的单元测试:在导入模块之前模拟 function - Unit test for Python AWS Lambda: mock function before module is imported 如何为Python socketserver请求处理程序编写单元测试? - How to write unit test for Python socketserver request handler? 如何在 python 中为这个特定函数编写单元测试? - How to write unit test for this particular function in python? 如何通过 python 中的单元测试为 init function 编写测试用例? - How to write test cases for a init function by Unit test in python? Python 中的 AWS Lambda:在 Lambda 函数处理程序中导入父包/目录 - AWS Lambda in Python: Import parent package/directory in Lambda function handler 如何为Python __del__函数编写单元测试用例 - How to write unit test case for Python __del__ function Python:如何为代表函数的实例变量编写单元测试? - Python: how to write unit test for instance variable representing a function? 在python中,如何为打开文件使用的函数编写单元测试? - In python, how to write unit test for a function is using with open file?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM