[英]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.