Reputation: 11621
I created an Azure Function v2 (.NET Core) and added a Core Class library that includes Unit Tests using xUnit. I then created a Build pipeline in Azure DevOps with the tasks Visual Studio build and Visual Studio Test.
But I repeatedly fail to build successfully respectively to have the Unit tests running successfully in the pipeline. Locally everything works fine.
What do I have to do to get the Function App build and unit tested successfully in the Azure DevOps Build pipeline?
Upvotes: 0
Views: 779
Reputation: 11621
Here are the steps that have made it work:
Create the Core Class Library
Reference the Azure Function project via "Add Reference"
Add NuGet packages to the class library -> xunit, xunit.runner.visualstudio and Microsoft.NET.Test.Sdk
Add classes to the class library as described here: https://learn.microsoft.com/en-us/azure/azure-functions/functions-test-a-function#create-test-classes
Go to to the .csproj file of the Azure Functions project as well as the class library for the unit tests and change
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
to
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<AzureFunctionsVersion>v2</AzureFunctionsVersion>
<RuntimeFrameworkVersion>2.1.1</RuntimeFrameworkVersion>
<PlatformTarget>AnyCPU</PlatformTarget>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
</PropertyGroup>
........................................................ ........................................................ ........................................................
Make sure that all files are added before checking in (TFVC) / pushing (Git)
Check in / Push
Upvotes: 1