0
votes

I created a MSTest2 project with Visual Studio 2017, which targets .NET 4.5.1 When I run testcases locally everything works, but when I commit them in my git repository (hosted by TFS servers), TFS will not publish the test results.

I attach part of the unittest logfile (with an error):

2018-02-08T12:12:18.4706988Z Attachments:
2018-02-08T12:12:18.4706988Z   <SOME PATH>/<FILENAME>.coverage
2018-02-08T12:12:18.4706988Z 
2018-02-08T12:12:18.4706988Z Total tests: 35. Passed: 35. Failed: 0. Skipped: 0.
2018-02-08T12:12:18.4706988Z Test Run Successful.
2018-02-08T12:12:18.4706988Z Test execution time: 9.6025 Seconds
2018-02-08T12:12:18.7988091Z ##[warning]Failed to publish test results: The given path's format is not supported.

I am using VS2017 and the .csproj file contains the following references

<Project ToolsVersion="15.0">
   <PropertyGroup>
            <TargetFramework>net451</TargetFramework>
            <IsPackable>false</IsPackable>
   </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
    <PackageReference Include="MSTest.TestAdapter" Version="1.1.14" />
    <PackageReference Include="MSTest.TestFramework" Version="1.1.14" />
  </ItemGroup>
</Project>

Is there anything I can do to make it work on TFS build on servers? I read MSTest2 does not work well together with TFS. Is there any workaround or any other technology?

Thanks in advance.

1

1 Answers

1
votes

For MSTest test project using dotnet Core, please use the dot net core task with Test verb and not the VSTest task/Run functional test tasks.

Then use publish test results task to publish your test results. Take a look at below sample:

  1. Remove the Visual Studio Test task
  2. Add the .NET Core task (I used version 1.*)

    a. Set the command to test

    b. Match the test projects in your repo according to your hierarchy (ex: test\**\*.csproj)

    c. Specify the value --logger:trx in the Arguments section

  3. Add the Publish Test Results task (I used version 2.*)

    a. Set the Test Result Format to VSTest

    b. Set the Test Results Files to **\*.trx

    c. Optionally, update the Search Folder; mine was $(System.DefaultWorkingDirectory)\test

    d. Check the Merge Test Results option

Soure Link

More details, you could also refer this tutorial-- TFS 2017 Build- MSTest v2 tests are not recognized