Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Devops UnitTest not finding ".deps.json" file

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.

like image 275
Celdus Avatar asked Mar 27 '20 18:03

Celdus


People also ask

What is the DEPS JSON file?

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)

Where do I put Runtimeconfig JSON?

json file. If you're just running the app, insert them directly into the [appname]. runtimeconfig.

What does dotnet test do?

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.


1 Answers

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
like image 140
DanMusk Avatar answered Sep 18 '22 08:09

DanMusk