c# – NUnit不服从属性继承

前端之家收集整理的这篇文章主要介绍了c# – NUnit不服从属性继承前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个NUnit的问题 – 想知道是否有任何想法.

我们使用的是NUnit 2.5.3.9345和C#3.5.

采取以下代码

public class UnitTestBase
{
    [TestFixtureSetUp]
    public void SetUpTestFixture()
    {
        //Do something in base
    }
}

[TestFixture]
public class SomeTestClass : UnitTestBase
{
    [TestFixtureSetUp]
    public void FixtureSetUp()
    {
        //Do something in test class
    }

    [Test]
    public void SomeTest()
    {
        //Some assertion
    }
}

根据documentation,如果我运行SomeTestClass.SomeTest(),UnitTestBase.SetUpTestFixture()应该在SomeTestClass.FixtureSetUp()之前调用.

不是这样 – 只有在派生类中不提供[TestFixtureSetUp]方法时,才会调用基本方法.

有什么想法吗?有我真的困惑!

谢谢.

解决方法

我没有问题.我用以下内容测试了结果:

衍生测试

[TestFixture]
public class DerivedTest : TestBase
{

    [TestFixtureSetUp]
    public void FixtureSetup()
    {

        File.AppendAllText("Out.txt",string.Format("TestFixtureSetUp From DerivedTest{0}",Environment.NewLine));
    }

    [TestFixtureTearDown]
    public void FixtureTearDown()
    {
        File.AppendAllText("Out.txt",string.Format("TestFixtureTearDown Down From DerivedTest{0}",Environment.NewLine));
    }

    [SetUp]
    public void Setup()
    {
        File.AppendAllText("Out.txt",string.Format("Setup From DerivedTest{0}",Environment.NewLine));
    }
    [TearDown]
    public void Down()
    {
        File.AppendAllText("Out.txt",string.Format("TearDown From DerivedTest{0}",Environment.NewLine));
    }

    [Test]
    public void DoATest()
    {
        File.AppendAllText("Out.txt",string.Format("Did a Test{0}",Environment.NewLine));
    }
}

TestBase

public class TestBase
{

    [TestFixtureSetUp]
    public void BaseTestFixtureSetUp()
    {
        File.AppendAllText("Out.txt",string.Format("TestFixtureSetUp From TestBase{0}",Environment.NewLine));
    }

    [TestFixtureTearDown]
    public void BaseTestFixtureTearDown()
    {
        File.AppendAllText("Out.txt",string.Format("TestFixtureTearDown From TestBase{0}",Environment.NewLine));
    }

    [SetUp]
    public void BaseSetup()
    {
        File.AppendAllText("Out.txt",string.Format("Setup From TestBase{0}",Environment.NewLine));
    }

    [TearDown]
    public void TearDown()
    {
        File.AppendAllText("Out.txt",string.Format("TearDown From TestBase{0}",Environment.NewLine));
    }
}

这产生以下输出

TestFixtureSetUp From TestBase
TestFixtureSetUp From DerivedTest
Setup From TestBase
Setup From DerivedTest
Did a Test
TearDown From DerivedTest
TearDown From TestBase
TestFixtureTearDown Down From DerivedTest
TestFixtureTearDown From TestBase

我能够使用ReSharper 5 beta和Nunit GUI v 2.5.3.9345(32位)测试输出

编辑在工作中,ReSharper 4.5中的测试运行程序无法正常运行,但是使用相应的NUnit.exe / NUnit-86.exe在x86和x64中运行内置测试项目可以生成有效的输出.

原文链接:https://www.f2er.com/csharp/97082.html

猜你在找的C#相关文章