1
votes

I am pretty new to CI/CD and mm currently struggling with getting VSTS to find my xUnit tests. My solution is a pure experiment, to try and isolate the problem and to learn. Before getting into my setup and what's been done so far, the result is this line in the VSTS build log:

Warning: No test is available in C:\agent\_work\1\s\Quotifier.Models.xUnit.Test\bin\Release\netcoreapp2.0\Quotifier.Models.xUnit.Test.dll. Make sure that installed test discoverers & executors, platform & framework version settings are appropriate and try again.

From having googled the message I interpret it as VSTS not being able to find an xUnit test adapter. Is that a correct assumption? Also, I see the terms "test adapter", "test runner" and "test explorer" alot. Are these terms the same thing? Having checked out this article it seems they are indeed the same thing. Can anyone clarify?

Now, for my setup ...

The xUnit test project is a .NET Core 2 class library referencing NUget packages xunit and xunit.runner.visualstudio (2.2.0). The test project is also referencing a shared class library called "Quotifier.Models" which contains the tested code.

To make it easier to diagnose I am running a local (on prem) build agent on my PC. This enables me to investigate the file structure.

The build step of my build definition was initially a "Visual Studio Build" that built the whole solution. I can see that the resulting binaries ends up in

C:\agent\_work\1\s\Quotifier.Models.xUnit.Test\bin\Release\netcoreapp2.0. Among the binaries are also xunit.runner.visualstudio.dotnetcore.testadapter.dll. Is this the xUnit test adapter VSTS can't find?

More googling tells me that the typical place for the test adapter to be found is in the $(Build.SourcesDirectory)\packages folder and, so, that's what the test step's "Path to custom test adapters" should be set to. That gave me this log entry:

Warning: The path 'C:\agent\_work\1\s\packages' specified in the 'TestAdapterPath' does not contain any test adapters, provide a valid path and try again..

I also checked that local folder and, indeed, the xunit NUget packages does not end up in there. Can anyone guess as to why?

Assuming the xunit.runner.visualstudio.dotnetcore.testadapter.dll is indeed the test adapter VSTS is looking for, I thought I should try and help it a bit. So I created a seperate MSBuild step and specified the output path via the "MSBuild arguments":

/p:OutputPath="$(build.binariesdirectory)/$(BuildConfiguration)/test-assemblies".

I then set the test step's "Path to custom test adapters" property to point at that same folder. With that I'm back to the original warning in the log:

Warning: No test is available in C:\agent\_work\1\b\release\test-assemblies\Quotifier.Models.xUnit.Test.dll. Make sure that installed ... bla ... bla

Now, to summarize ...

  • running xUnit test projects out of the box doesn't work with VSTS
  • The xUnit NUget packages does not end up in the /**/packages folder
  • I am assuming the xunit.runner.visualstudio.dotnetcore.testadapter.dll is the test adapter needed. Is this assumtion correct?

I'm out of ideas for now so any hints, links or suggestions will be greatly appreciated.

1
You can do it with VSTS. Are you using the "VSTEST"-task to run your tasks or "dotnet test" ? If the tests are a netcore2-project you are supposed to run the tests with "dotnet test" - D.J.
And your xunit-packages are not supposed to end up in "packages"-directory. The netcore2 projects handle nuget-packages differently and will reference them from the local nuget-cache - D.J.
I can't find a test step called "dotnet test". I also checked the VSTS "Marketplace" but still no such step available. Where can I find that step? - Jonas Rembratt
The task is called ".NET Core" and has a command dropdown where you select build/restore/test etc... You also need to add "NET Core Tool Installer" if you are using a hosted agent - D.J.
Running a dotnet test step did the trick! It now finds the tests and I can see them passing in the log. Go ahead and write a reply so I Can mark it as the answer. :-) Also: Is there a way to produce test- and code coverage results? I tried adding the argument --results-directory $(Build.SourcesDirectory)\TestResults but no such directory is getting created or populated with a result. - Jonas Rembratt

1 Answers

4
votes

Use "dotnet test" to run Your NetCore-UnitTests. The task is called ".NET Core" and has a command dropdown where you select build/restore/test etc... You also need to add "NET Core Tool Installer" if you are using a hosted agent

And your xunit-packages are not supposed to end up in "packages"-directory. The netcore2 projects handle nuget-packages differently and will reference them from the local nuget-cache