How To Run Xunit in VisualStudioOnline Build

2019-08-12 06:01发布

问题:

I've VS2015 RC project in my visual studio online account. In this project the tests are written with xunit.

In the project I've added the following nuget packages

  <package id="xunit" version="2.1.0-beta3-build3029" targetFramework="net46" userInstalled="true" />
  <package id="xunit.abstractions" version="2.0.0" targetFramework="net46" userInstalled="true" />
  <package id="xunit.assert" version="2.1.0-beta3-build3029" targetFramework="net46" userInstalled="true" />
  <package id="xunit.core" version="2.1.0-beta3-build3029" targetFramework="net46" userInstalled="true" />
  <package id="xunit.extensibility.core" version="2.1.0-beta3-build3029" targetFramework="net46" userInstalled="true" />
  <package id="xunit.runner.visualstudio" version="2.1.0-beta3-build1069" targetFramework="net46" userInstalled="true" />

With this I can see and run the Tests in the VisualStudio TestPane .

Now in the Online configuration I cann add the VisualStudio Test Action. But it seems like it is only looking for MSTestTests.

In the log i can also find:

Warning: Using Isolation mode to run the tests as diagnostic data adapters were enabled in the runsettings. Use the /inIsolation parameter to suppress this warning.

Warning: No test is available in C:\a\7588a0f7\CRM\src\BoundContextes\SharedKernel\SharedKernel.Tests\bin\Debug\SharedKernel.Tests.dll. Make sure that installed test discoverers & executors, platform & framework version settings are appropriate and try again.

In this action I can see that there is a "Path To Custom TEst Adapter". I Asume that I have to set this to something like a XUnit-TestAdapter? But I can't find out what I should enter there Nor where to get this ?

回答1:

You should set your Path to Custom Test Adapters to the location of the "packages" folder.

For example I keep my packages next to my Solution file in the root of my repo, so I set my path to:

$(Build.SourcesDirectory)\packages



回答2:

Like you I am using MSBuild to build my solution (I don't have visual studio installed on the build server)

So this is what I did.

  1. Install the xunit.runner.msbuild nuget package in the Test project.
  2. Modify you project file by uncommenting the AfterBuild target and adding the following task (notice the xml file name, that is important for the next step)

    <Target Name="AfterBuild" Condition=" '$(BuildingInsideVisualStudio)' == ''">
        <xunit Assemblies="$(TargetPath)" Xml="$(TargetDir)TEST-Portal.xml" />
    </Target>
    

    Also notice the target condition. That is preventing the target to run when you build from Visual Studio, since you probably are using the xunit.runner.visualstudio

  3. Add the Publish Test Results step after your MSBuild step and setup a proper file name for your results based on what you did in the previous step

After that commit your changes and queue a new build, you should see the test results on the summary tab of your build.

If you still want to use the xunit.runner.visualstudio on VSTS then follow the steps in xUnit website.