I am in the process of upgrading our existing solution to .Net 4.6.1 and have been unable to get our unit tests to run during a server build. Locally they run as expected an
I ran into the same problem in VSTS with .Net 4.6.2. If you are seeing this from your VSTS console output, the workaround provided by @Sushil still works in VSTS and is needed. Unfortunately the "Test Assemblies" task provided by Microsoft passes, so you really don't even know there is a problem unless you check the output and find none of your tests actually executed!
In my case, I had to:
Convert test project to netcore 2.0 (was netstandard 2.0)
Add nuget package xunit.runner.visualstudio
Reference: http://www.neekgreen.com/2017/11/20/xunit-no-test-is-available/
Using .Net Core with a build pipeline in TFS 2017, my Visual Studio Test step was passing without actually executing any tests. Had to edit the step, "Advanced Execution Options" -> "Other console options" to include:
/framework:".NETCoreApp,Version=v2.0"
(That field also contains /platform:x64
)
Make sure that you've got the "Microsoft.NET.Test.Sdk" nuget installed.
This question is obviously being found by people with a range of scenarios, my answer will cover running XUnit tests on a .NET Core project using build pipeline on Azure DevOps but may help others too.
otherConsoleOptions: '/framework:.NETCoreApp,Version=v3.1'
to the inputs
of your VSTest@2
step (with the version number set to whatever version of .NET Core you are using). See this documentation for more info.failOnMinTestsNotRun: true
so that the build pipeline will report a failure if zero tests are run.The library 'hostpolicy.dll' required to execute the application was not found
. You can solve this by changing your filter from the default **\*test*.dll
to **\*test.dll
(note the removed asterisk), or some other pattern which will match your test project's DLL. The reason for this is that XUnit places a file called testhost.dll
in the output directory, as explained in this github issue.If you are using the older pipelines which do not use yaml, the same options should be available. This answer covers adding the framework, I assume there will also be an option to "Fail the task if a minimum number of tests are not run" or something similar.
This is just to recap the solution brought forward by @Sushil earlier.
This is a known issue in Team Foundation Server 2015 RTM + Update 1 and will be fixed in Update 2, reference.
There is a workaround described by @Sushil here, which includes adding a .runsettings file that forces the test runner to older .Net framework (please not that you have to specify it through the "Add/Edit Test Run" dialog as adding it directly in the build process editor will be ignored).