I created an asp.net core webapi project and created an coresponding xUnitTest for it. When I am running the UnitTest on my local maschine the UnitTest runs without any problems. I use the XUnit with its visualstudio runner. Here are the references of my UnitTest project:
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="3.1.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="Moq" Version="4.13.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.assert" Version="2.4.1" />
<PackageReference Include="xunit.extensibility.core" Version="2.4.1" />
<PackageReference Include="xunit.extensibility.execution" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
When I now run the unittest via Azure Devops, they run successfully and give me the following output:
Created test run: 156
Publishing test results: 35
Publishing test results to test run '156'.
TestResults To Publish 35, Test run id:156
Test results publishing 35, remaining: 0. Test run id: 156
Published test results: 35
Publishing Attachments: 2
Failed tests: 0; Total tests: 35;
The problem I have is, that later I get an exception, that the ".deps.json" file was not found:
Unable to find d:\a\1\s\<project-path>\obj\Release\netcoreapp3.1\<project>.deps.json. Make sure test project has a nuget reference of package "Microsoft.NET.Test.Sdk".
I then checked if I can search for the binary folder, but then no test project is found. I also tried using the "DotNetCoreCLI@2" task and the "VSTest@2" task, both produce the same problem. Here is the yaml file I use:
# UnitTests
- task: VSBuild@1
inputs:
solution: '**/<projectnamespace>.UnitTests.csproj'
vsVersion: 16.0 #also tried without this line
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: DotNetCoreCLI@2
inputs:
command: test
projects: '**UnitTests.dll'
arguments: '--configuration $(buildConfiguration)'
- task: VSTest@2
inputs:
testSelector: testAssemblies
testAssemblyVer2: '**bin\**UnitTests*.dll'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
diagnosticsEnabled: true
codeCoverageEnabled: true
Both test-task will run the test and then are "failed" because the ".deps.json" file was not found.