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