单元测试 Azure Functions 和 .csx 文件 [英] Unit Testing Azure Functions and .csx Files

查看:9
本文介绍了单元测试 Azure Functions 和 .csx 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Azure Functions 抽象出大量依赖项,例如队列库和 Azure 表.所以从单元测试依赖模拟的角度来看,编码工作更少(因此维护也更少).

假设我们使用 Visual Studio 2015 进行本地开发

  • 如何对单个 Azure 函数进行单元测试(对集成测试不感兴趣)?但是,最好在 xUnit 中,任何框架都可以.
  • 我一般如何对 .csx 文件中的函数进行单元测试?

解决方案

就目前而言,实际上不可能对这些文件进行单元测试.出于这个原因(以及其他一些原因),我们在从 Visual Studio 开发基于 .cs 和更多标准 .NET 库的函数时切换到了不同的模型.这使得 Visual Studio 中的很多事情变得更加正常".有关详细信息,请参阅doc.

更新:另见 无法在与单元测试项目相关的 Azure Functions 单元测试中加载文件或程序集 System.Net.Http, Version=4.1.1.0.p>

Azure Functions abstract plenty of dependencies like queue libraries and Azure Tables. So from a Unit Test dependencies mocking perspective, there is less coding effort (and accordingly less maintenance).

Assuming we are developing locally using Visual Studio 2015

  • How can I unit test (not interested in integration test) a single Azure Function? Preferably in xUnit, however, any framework would do.
  • How can I unit test a function in a .csx file in general?

解决方案

As it stands, it's not really possible to unit test those files. For that reason (and a number of others), we have switched to a different model when developing Functions from Visual Studio, based on .cs and more standard .NET libraries. This makes a lot of things more 'normal' in Visual Studio. See doc for details.

Update: see also Could not load file or assembly System.Net.Http, Version=4.1.1.0 in Unit Test for Azure Functions relating to unit test projects.

这篇关于单元测试 Azure Functions 和 .csx 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆