在Azure DevOps中运行Azure Function v1单元测试

时间:2019-10-14 14:17:31

标签: c# azure azure-devops azure-functions mstest

我有一个Azure Function v1,在Azure DevOps中具有有效的生成和发布管道。到目前为止,还没有任何单元测试。测试可以在本地Visual Studio 2019上顺利运行。但是我无法使它们在Azure DevOps中的构建管道上运行。

我在构建管道中使用的是Visual Studio构建,而不是dotnet.exe,因为这就是我在这里工作的方式。

当我尝试添加dotnet test时,会出现以下错误:

...\Roslyn\Microsoft.CSharp.Core.targets(59,5): error MSB4062: The "Microsoft.CodeAnalysis.BuildTasks.Csc"
task could not be loaded from the assembly ...\Roslyn\Microsoft.Build.Tasks.CodeAnalysis.dll.
Assembly with same name is already loaded Confirm that the <UsingTask> declaration is correct,
that the assembly and all its dependencies are available, and that the task contains
a public class that implements Microsoft.Build.Framework.ITask.

当我尝试使用Visual Studio Test运行测试时,出现以下错误:

"An exception occurred while invoking executor 'executor://mstestadapter/v2':
Method 'get_DataRow' in type 'Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.TestContextImplementation'
from assembly 'Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices,
Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' does not have an implementation."

我应该怎样做才能使构建管道运行Azure Function v1的测试?

2 个答案:

答案 0 :(得分:1)

您需要添加Visual Studio测试任务:

Visual Studio Test

答案 1 :(得分:0)

解决方案是将MSTest.TestAdapter和MSTest.TestFramework nuget的版本从2.0.0降级到1.4.0,并开始运行(并通过)测试。