10

I have an issue finding how to display tests according to class hierarchy in MS Test Runner (same in Resharper test runner) using XUnit.

I have structure similar to below example:

public class ManagerTests
{
    public class Create
    {
        public class When_Something
        {
            [Fact]
            public void Then_this_should_happen()
            {
            }
        }

        public class When_Something_else
        {
            [Fact]
            public void Then_else_should_happen()
            {
            }
        }
    }
}

I want this displayed as (in test runner):

ManagerTests
    Create
        When_something
            Then_this_should_happen
        When_something_else
            Then_else_should_happen

But what i seem to end up with is:

ManagerTests+Create+When_something
    Then_this_should_happen
ManagerTests+Create+When_something_else
    Then_else_should_happen

I looked at the xunit config settings but did not seem to find any way of adjusting this. Ive tried different grouping options but did not find anything that fixed this. Found some older posts asking questions about this (as this one), but as of yet i have not found how to do it.

So question is: How can i stop the nested classname concatenation (class1+class2+class3) and present their hierarchy instead?

Tree55Topz
  • 1,102
  • 4
  • 20
  • 51
Base
  • 1,061
  • 1
  • 11
  • 27

1 Answers1

0

I used inheritance. A class with all the setup I want repeated.

namespace ManagerTests
{
  public class RootTest : IDisposable
  {
    ...
  }
}

Then a class for each test with a different namespace

namespace ManagerTests
{
  public class RootTest : IDisposable
  {
    ...
  }

  namespace Create
  {
    [Collection(nameof(Test1Class))]
    public class Test1Class : RootTest
    {
      ...
    }

    [Collection(nameof(Test2Class))]
    public class Test2Class : RootTest
    {
      ...
    }
  }
}

I think what you want are namespaces instead of classes?

The reason for Test1Class & Test2Class is for them to run in parallel

I think classes should work like namespaces here.

E_net4
  • 27,810
  • 13
  • 101
  • 139
TamusJRoyce
  • 817
  • 1
  • 12
  • 25