【问题标题】:How do I make Xunit test class and use constructor parameters like TestFixture with parameters in Nunit?如何制作 Xunit 测试类并在 Nunit 中使用带有参数的构造函数参数(如 TestFixture)?
【发布时间】:2020-03-24 12:42:02
【问题描述】:

在 Nunit 中,我可以这样做:

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

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

【问题讨论】:

    标签: c# xunit


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-10-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-03
      相关资源
      最近更新 更多