microsoft / vstest

Visual Studio Test Platform is the runner and engine that powers test explorer and vstest.console.
MIT License
897 stars 323 forks source link

MSTest V2 doesn't output "TestCategory" to .TRX files (but V1 did/does) #4142

Closed nohwnd closed 4 months ago

nohwnd commented 4 years ago

Originally posted by @MikePanitz-CCC in testfx-docs

Hello!

Using MSTest.Framework (1.3.2) and the following code:

       [TestMethod]
        [TestCategory("Instructor chosen Grading Category Goes Here")]
        public void Basic_Fail_2()
        {
            bool correctAnswer = false;
            Assert.IsTrue(correctAnswer, "This message will be displayed when the test fails");
        }

I can run the tests from the command line to generate a .TRX / .XML file that includes the following

<TestDefinitions>
    <UnitTest name="Basic_Fail_2" storage="c:\mikesstuff\pers\dropbox\work\website\courses\bit143\lessons\lesson_03\nunit_materials\do_not_upload\mstest_using_dotnetcore\mstest_using_dotnetcore\bin\debug\netcoreapp2.0\mstest_using_dotnetcore.dll" id="468bfd94-b2bd-e0b2-dfaa-b056c00e7ae3">
      <TestCategory>
        <TestCategoryItem TestCategory="Instructor chosen Grading Category Goes Here" />
      </TestCategory>
      <Execution id="4afac95c-6b8a-4996-85d6-c8087f2e3203" />
      <TestMethod codeBase="C:\MikesStuff\Pers\Dropbox\Work\Website\Courses\BIT143\Lessons\Lesson_03\NUnit_Materials\DO_NOT_UPLOAD\MSTest_Using_DotNetCore\MSTest_Using_DotNetCore\bin\Debug\netcoreapp2.0\MSTest_Using_DotNetCore.dll" adapterTypeName="executor://mstestadapter/v2" className="MSTest_Using_DotNetCore.NUnit_Tests_Basic_Demonstrations" name="Basic_Fail_2" />
    </UnitTest>

However, when using MSTest V2 the .TRX file includes only this:

  <TestDefinitions>
   <UnitTest name="Basic_Fail_2" storage="c:\mikesstuff\pers\dropbox\work\website\courses\bit143\lessons\lesson_03\nunit_materials\do_not_upload\unittestdemo_core3_1\bin\debug\netcoreapp3.1\unittestdemo_core3_1.dll" id="daba9da9-b9e4-3614-3841-237a64d89d56">
      <Execution id="73801b0b-bd2c-4b31-ac77-2fb1e0417270" />
      <TestMethod codeBase="C:\MikesStuff\Pers\Dropbox\Work\Website\Courses\BIT143\Lessons\Lesson_03\NUnit_Materials\DO_NOT_UPLOAD\UnitTestDemo_Core3_1\bin\Debug\netcoreapp3.1\UnitTestDemo_Core3_1.dll" adapterTypeName="executor://mstestadapter/v2" className="PCE_StarterProject.NUnit_Tests_Basic_Demonstrations" name="Basic_Fail_2" />
    </UnitTest>

(Note the missing TestCategory element, and therefore the missing TestCategoryItemchild element(s).)

I'd love to be able to 'tag' tests using the TestCategory attribute and have that attribute be accessible in the resulting .TRX file

ghost commented 4 years ago

In case it helps, here's the the .CSPROJ file for V2 (which does not include TestCategory in the output file):

<Project Sdk="Microsoft.NET.Sdk">
you
  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>

    <IsPackable>false</IsPackable>

    <StartupObject>PCE_StarterProject.Program</StartupObject>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
    <PackageReference Include="MSTest.TestAdapter" Version="2.1.0" />
    <PackageReference Include="MSTest.TestFramework" Version="2.1.0" />
    <PackageReference Include="coverlet.collector" Version="1.2.0" />
  </ItemGroup>

  <ItemGroup>
    <Folder Include="XML_OUTPUT\" />
  </ItemGroup>

</Project>

here's the .CSPROJ file for V1, which does include TestCategory in the output file:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netcoreapp2.0</TargetFramework>

    <IsPackable>false</IsPackable>

    <StartupObject>MSTest_Using_DotNetCore.Program</StartupObject>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
    <PackageReference Include="MSTest.TestAdapter" Version="1.3.2" />
    <PackageReference Include="MSTest.TestFramework" Version="1.3.2" />
  </ItemGroup>

</Project>

The command line that I used to generate the .TRX file looks more-or-less like this:

"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe" bin\Debug\netcoreapp3.1\UnitTestDemo_Core3_1.dll /Logger:trx /ResultsDirectory:XML_OUTPUT

Evangelink commented 1 year ago

I am moving this issue to Test Platform because MSTest correctly emits the property, problem is on Test Platform side which isn't translating it into the trx.

nohwnd commented 4 months ago

This is a new feature and won't be implemented, we are focusing on adding new features to Testing.Platform instead. https://aka.ms/testingplatform