我在寻找如何使用 XUnit 在 MS Test Runner(与 Resharper 测试运行器中相同)中根据类层次结构显示测试时遇到问题。
我的结构类似于下面的示例:
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()
{
}
}
}
}
我希望将其显示为(在测试运行程序中):
ManagerTests
Create
When_something
Then_this_should_happen
When_something_else
Then_else_should_happen
但我最终得到的似乎是:
ManagerTests+Create+When_something
Then_this_should_happen
ManagerTests+Create+When_something_else
Then_else_should_happen
我查看了 xunit 配置设置,但似乎没有找到任何调整的方法。我尝试了不同的分组选项,但没有找到任何解决此问题的方法。发现一些较旧的帖子询问有关此的问题(如this),但到目前为止我还没有找到如何做到这一点。
所以问题是:我怎样才能停止嵌套的类名串联(class1+class2+class3)并呈现它们的层次结构?
我使用了继承。一堂包含我想要重复的所有设置的课程。
namespace ManagerTests
{
public class RootTest : IDisposable
{
...
}
}
然后为每个测试创建一个具有不同命名空间的类
namespace ManagerTests
{
public class RootTest : IDisposable
{
...
}
namespace Create
{
[Collection(nameof(Test1Class))]
public class Test1Class : RootTest
{
...
}
[Collection(nameof(Test2Class))]
public class Test2Class : RootTest
{
...
}
}
}
我想你想要的是命名空间而不是类?
Test1Class & Test2Class 的原因是为了让它们并行运行
我认为类应该像命名空间一样工作。