NUnit - 在SetUpFixture上不允许使用TestFixtureSetUp方法

Chr*_*her 8 c# nunit

我正在尝试重新组织一些集成测试,以便他们使用[SetUpFixture] NUnit属性在同一程序集中的其他类中使用公共类创建数据库和数据库中所需的数据.

我有 :

namespace Tests;

public class TestBaseClass : SolutionBaseClass
{
    public void Setup()
    {
        base.CreateDatabase();
        base.CreateData();
    }

    public void Teardown()
    {
        base.DestroyDatabase();
    }
}

[SetUpFixture]
public class Setup : TestBaseClass
{
    [SetUp]
    public void Setup()
    {
        base.Setup();
    }

    [TearDown]
    public void Teardown()
    {
        base.Teardown();
    }
}
Run Code Online (Sandbox Code Playgroud)

然后个别测试夹具类:

namespace Tests.Services;

[TestFixture]
public class LibraryTest : TestBaseClass
{
    [TestFixtureSetUp]
    public void SetupTests()
    {
        // I know am calling the same Setup twice once from SetUpFixture and TestFixture, 
        // I have handled it so that only one Database/Data gets set up once (for safety mostly!)
        base.SetUp();

        // Other class initialisations.
    }
}
Run Code Online (Sandbox Code Playgroud)

任何想法我做错了,我认为这是使用继承模型的问题,因为你可以告诉我从别人继承这个!

谢谢.

Den*_*kiy 12

在NUnit 3中,应该对[SetUpFixture]类的静态方法使用OneTimeSetUpAttribute和OneTimeTearDownAttribute.资料来源:http://bartwullems.blogspot.nl/2015/12/upgrading-to-nunit-30-onetimesetup.html

在NUnit 2.0中

[SetUpFixture]
class TestHost
{
    [SetUp]
    public static void AssemblyInitalize()
    {
      //Global initialization logic here
    }
}
Run Code Online (Sandbox Code Playgroud)

在NUnit 3.0中

[SetUpFixture]
class TestHost
{
    [OneTimeSetUp]
    public static void AssemblyInitalize()
    {
      //Global initialization logic here
    }
}
Run Code Online (Sandbox Code Playgroud)


Iht*_*has 10

In NUnit 3.0 TestFixtureSetUpandTestFixtureTearDown已重命名为OneTimeSetUpand OneTimeTearDown

以下是上述更改的文档链接: