为什么会收到“ OneTimeSetUp:找不到合适的构造函数...”?

时间:2019-06-14 05:59:07

标签: nunit nunit-3.0

我正在使用NUnit3,并尝试在以下类层次结构中使用TestFixtureSource

public class AtataTestFixtureData
{
    public static IEnumerable FixtureParams
    {
        get
        {
            yield return new TestFixtureData(new AtataConfigContainer
                                             {
                                                 AtataJsonConfig = new BaseAtataConfig()
                                             });
        }
    }
}

[TestFixtureSource(typeof(AtataConfigContainer), nameof(AtataTestFixtureData.FixtureParams))]
public class AtataTestsWithDbBase : OzCsTestsWithDbBase, IAtataAbpTests
{
    public AtataTestsWithDbBase()
    {

    }

    public AtataTestsWithDbBase(AtataConfigContainer aAtataConfigContainer)
    {
        AtataAbpTestsAdapter = AtataAbpTestsAdapter.Instance;
        AtataConfigContainer = aAtataConfigContainer;
    }
}

public class SomeSiteComAuTestsBase : AtataTestsWithDbBase
{
    public SomeSiteComAuTestsBase(AtataConfigContainer aAtataConfigContainer) : base(aAtataConfigContainer)
    {
    }
}

[TestFixture]
public class IndexTests : SomeSiteComAuTestsBase
{
    /// <summary>
    ///     Class constructor.
    /// </summary>
    public IndexTests(AtataConfigContainer aAtataConfigContainer) : base(aAtataConfigContainer)
    {
    }

    [Test]
    public void Get()
    {
        //Arrange

        //Act
        IndexPageObject indexPage = Go.To<IndexPageObject>();

        //Assert
    }
}   

当我运行IndexTests.Get()时,我得到了异常OneTimeSetUp: No suitable constructor was found,但根据public IndexTests(AtataConfigContainer aAtataConfigContainer) : base(aAtataConfigContainer),我有了所需的构造函数。

我在这里想念什么?

1 个答案:

答案 0 :(得分:1)

您会收到此错误,因为您的IndexTests类具有一个带参数的构造函数,但是您的TestFixtureSource在基类上。 TestFixtureSource必须在您的IndexTests上。 TestFixtureSource属性不会被继承。