我正在使用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)
,我有了所需的构造函数。
我在这里想念什么?
答案 0 :(得分:1)
您会收到此错误,因为您的IndexTests
类具有一个带参数的构造函数,但是您的TestFixtureSource
在基类上。 TestFixtureSource
必须在您的IndexTests
上。 TestFixtureSource
属性不会被继承。