NUnit 3动态ValueSourceAttribute

问题描述 投票:0回答:1

我必须将NUnit 2.x测试转换为NUnit 3.x测试,目前的情况是,在这些测试和many类中,有一个带有测试的基类,并且在abstract IEnumerable中使用了ValueSource属性。继承此基类并覆盖此属性。问题是如何将这些测试转换为必须为ValueSource的NUnit3.x。每个基本子代也具有不同的TestCategory.Subcategory

[Category(TestCategory.Transformations)]
public abstract class Transformations
{
    [Test]
    public void TransformTest([ValueSource("TestDataSource")] TransformTestSource source)
    {
        // some test logic
    }

    protected abstract IEnumerable<TransformTestSource> TestDataSource { get; }
}

[TestFixture]
[Category(TestCategory.Transformations)]
[Category(TestCategory.Subcategory.Example1)]
public class ChildExample1
{
    protected override IEnumerable<TransformTestSource> TestDataSource
    {
        get { /* get data for example from database, or file */ }
    }
}

在我看来,唯一的方法是从抽象类中删除抽象属性定义,并在每个子类中定义此属性,但这听起来很糟糕。有更好的方法吗?

EDIT:有时,子类中还有一些其他测试,因此这些类并不总是仅用于数据填充。

c# nunit nunit-3.0
1个回答
0
投票

该基类必须是抽象的,否则NUnit将实例化它并运行它包含的测试。当然,当实例化基类时,它还将重新运行相同的测试。仅在基类上运行测试时,这充其量只能使人感到困惑,而在最坏的情况下则会产生错误。

您在问题中使用术语动态

© www.soinside.com 2019 - 2024. All rights reserved.