c# - xunit 是否有参数化测试夹具?

标签 c# unit-testing testing xunit xunit.net

xunit.net 是否支持像 nunit 这样的“参数化测试夹具”(参见下面的示例代码)。请注意,我不是在寻找 IUseFixture<T>[Theory]因为它们不提供与 Parameterized Test Fixtures 相同的功能

[TestFixture("hello", "hello", "goodbye")]
[TestFixture("zip", "zip")]
[TestFixture(42, 42, 99)]
public class ParameterizedTestFixture
{
    private string eq1;
    private string eq2;
    private string neq;

    public ParameterizedTestFixture(string eq1, string eq2, string neq)
    {
        this.eq1 = eq1;
        this.eq2 = eq2;
        this.neq = neq;
    }

    public ParameterizedTestFixture(string eq1, string eq2)
        : this(eq1, eq2, null) { }

    public ParameterizedTestFixture(int eq1, int eq2, int neq)
    {
        this.eq1 = eq1.ToString();
        this.eq2 = eq2.ToString();
        this.neq = neq.ToString();
    }

    [Test]
    public void TestEquality()
    {
        Assert.AreEqual(eq1, eq2);
        if (eq1 != null && eq2 != null)
            Assert.AreEqual(eq1.GetHashCode(), eq2.GetHashCode());
    }

    [Test]
    public void TestInequality()
    {
        Assert.AreNotEqual(eq1, neq);
        if (eq1 != null && neq != null)
            Assert.AreNotEqual(eq1.GetHashCode(), neq.GetHashCode());
    }
}

最佳答案

关于c# - xunit 是否有参数化测试夹具?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28211431/

相关文章:

spring - 如何在 AbstractTransactionalJUnit4SpringContextTests 事务中执行 junit 规则?

reactjs - 语法错误: Cannot use import statement outside a module Jest when node modules are ignored

c# - 从 C# 到 C++ 的数组再返回,没有不安全的代码

python - 如何测试变量是否为 pd.NaT?

unit-testing - 模拟 DBSet,EF 模型优先

javascript - 如何在 Jasmine.js 中使用带有 toHaveBeenCalledWith 的 spy 和可变数组?

php - 拉维尔 5 : test artisan migrate with path

c# - 如何获取特定类型的所有部分

c# - 人们如何在 C# 中重用混合风格?

c# - .Net Framework 4.0 中的 ASP.NET Web 服务去了哪里?