简体   繁体   English

如何为用C#编写的Azure Function应用编写单元测试?

[英]How can i write unit test for Azure Function App written in c#?

I have to write Unit test for azure function based app in Nunit3 as these function are developed in c# ? 我必须在Nunit3中为基于天蓝色函数的应用编写单元测试,因为这些函数是在C#中开发的?

The confusion is that , normal code is tested by creating mock object , then call method and then assert , but i am unable to do in case of Azure function as it has only method Run(). 令人困惑的是,正常代码是通过创建模拟对象,然后调用方法,然后断言来测试的,但是在Azure函数的情况下我无法执行,因为它只有方法Run()。

What are best way to tackle this problem ? 解决此问题的最佳方法是什么?

I would put the logic you want to test in a method in a separate class, that way you can write tests for that class as you normally would. 我会将要测试的逻辑放在一个单独的类中的方法中,这样您就可以像往常一样为该类编写测试。 Then in your Azure Function's Run method you can instantiate that class and call the method. 然后,可以在Azure函数的Run方法中实例化该类并调用该方法。

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

相关问题 如何为C#Azure功能编写单元测试? - How do I write Unit Test for C# Azure Function? 你能用C#编写单元测试程序集来测试用VB编写的程序集吗? - Can you write a unit test assembly in C# to test against an assembly written in VB? 当 function 必须写入标准输出时,我如何对 C# function 进行单元测试 - How do I unit test a C# function when that function must write to stdout 如何为具有带参数运行方法的 azure 函数编写单元测试? - How can I write unit test for azure function which has run method with parameter? Azure Function C# 中的单元测试 - Unit Test in Azure Function C# I created this Http Azure function with SendGrid and not sure how to write a unit test to call it with different email test case - I created this Http Azure function with SendGrid and not sure how to write a unit test to call it with different email test case 如何使用 Ms unit project c# 代码为逻辑应用程序步骤编写单元测试? - How do I write unit test for logic apps steps using Ms unit project c# code? 如何对这个C#扩展方法进行单元测试? - How can I unit test this C# extension method? 如何在C#中对单元测试性能优化进行单元测试? - How can I unit test performance optimisations in C#? 如何导出 C# 单元测试的结果? - How can I export the results of a C# unit test?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM