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.
deps. json will mean the host will blindly enumerate all . dll files in the application directory and use those as the "entire app". This typically means: Portable apps may not work (building with no RID specified will produce a portable app)
json file. If you're just running the app, insert them directly into the [appname]. runtimeconfig.
The dotnet test command builds the solution and runs a test host application for each test project in the solution. The test host executes tests in the given project using a test framework, for example: MSTest, NUnit, or xUnit, and reports the success or failure of each test.
In addition to ignore the obj
folder with !**\obj\**
, from .NET 5 we also had to ignore a ref
folder inside the bin
folder; !**\bin\**\ref\**
. Not ignoring this caused 2 files matching UnitTests.dll to be found, and the dll from the ref
folder would fail with the error: UnitTests.deps.json file was not found
What is this ref-folder?
Now our test-task looks like this:
- task: VSTest@2
inputs:
testSelector: 'testAssemblies'
testAssemblyVer2: |
**\*UnitTests.dll
!**\*TestAdapter.dll
!**\obj\**
!**\bin\**\ref\**
searchFolder: '$(System.DefaultWorkingDirectory)'
runTestsInIsolation: true
codeCoverageEnabled: true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With