ReSharper Unit Test Explorer shows tests as Uncategorized when grouping by test category

Answered

Environment:
Visual Studio 2022 17.4.3
ReSharper 2022.3.1 Build 223.0.20221218.114821
.NET 6 (or 7)
c# 10

We wanted to avoid the use of string literals when setting the TestCategory attribute, we felt that an enumeration would be a better way to define test categories as this allows for easier maintenance across hundreds of tests. We also opted to adopt a slightly different terminology, using test traits instead as opposed to test categories by inheriting from TestCategoryBaseAttribute and making the constructor of our class take an arbitrary number of traits, and overriding the TestCategories method, we are able to use the Enum.GetName method to retrieve the string representation of each Trait passed into the constructor.

While using Visual Studio's native Test Explorer, we can group tests by category using this process, but have noticed that with ReSharper's Unit Test Explorer, grouping by any selection that includes category does not properly enumerate the tests in the same manner as the MS Test Explorer and instead lists the tests under the parent 'Uncategorized' (screen shot beloiw)!

I have uploaded the sample project used to illustrate this submission (Upload ID: 2023_01_10_K4KJSdSiB3h83mjnTBwrz7) and have posted sample code after the screen shot:

using FluentAssertions;
namespace SimpleTestProject.TestMethods;

[TestClass]
public class UnitTests2 : UnitTestBase
{
  [TestMethod, TestTraits(TestTrait.Functional, TestTrait.Smoke, TestTrait.Unit)]
  [Description("Assert that the sum of two values are equal")]
  public void AdditionOfTwoNumbersShouldBeEqual()
  {
      const int actual = a + b;
      const int expected = 3;
      actual.Should().Be(expected, $" the sum of the values {actual} was expected to be {expected}!");
  }

  [TestMethod, TestTraits(TestTrait.Functional, TestTrait.Smoke, TestTrait.Unit)]
  [Description("The sum of two integer values should not be equal")]
  public void AdditionOfTwoNumbersShouldNotBeEqual()
  {
      const int actual = a + b;
      const int expected = 4;
      actual.Should().NotBe(expected, $" the sum of the values {actual} was not expected to be {expected}!");
  }
}

public class TestTraitsAttribute : TestCategoryBaseAttribute
{
    private readonly IList<TestTrait> _traits;

    public TestTraitsAttribute(params TestTrait[] categories)
    {
        _traits = categories;
    }

    public override IList<string?> TestCategories => _traits
        .Select(c => Enum.GetName(typeof(TestTrait), c))
        .ToList();
}

public enum TestTrait
{
    Debug,
    Functional,
    Smoke,
    Todo,
    Unit
}
0
3 comments

Ironically, I cannot reliably reproduce the behavior in the test project with only 4 units that I attached, yet the issue is prevalent in our test automation solution that has hundreds of tests!

0

Having added additional unit test classes to the sample project, I am once again able to reproduce the issue with ReSharper classifying tests as Uncategoried in the Unit Test Explorer regardless of whether tests have a single or multiple test category (traits).

0

Hello Mes6073,

Just for the history, the issue is confirmed as RSRP-491113 Unit Test Explorer shows tests as Uncategorized when grouping by test category

0

Please sign in to leave a comment.