如何进行 Xunit 测试 class 并在 Nunit 中使用带有参数的 TestFixture 等构造函数参数?

How do I make Xunit test class and use constructor parameters like TestFixture with parameters in Nunit?

在 Nunit 中我可以这样做:

[TestFixture("param1")]
[TestFixture("param2")]
public class MyTestFixture
{
    public MyTestFixture(string param) { /* more code */ }
    /* more code */
}

之后classMyTestFixture里面的所有测试和测试用例都会运行两次,一个一个使用TestFixture属性中的参数。 Xunit 不使用属性 TestFixture,那么我如何在不在 InlineData 中的每个测试中指定这两个参数的情况下做类似的事情?如果这样做,它会使我的测试代码中的属性数量加倍。我可以编写带参数的构造函数,但我没有找到在那里传递数据的方法。我该怎么做?

看起来 XUnit 开发人员关闭了这个问题并提到他们不会在 2015 年添加对此的支持:

https://github.com/xunit/xunit/issues/352

GitHub 线程中的一些用户发布了他们的替代解决方案,以解决缺乏对参数化 TestFixtures 的支持,这可能有助于解决您的问题。