我们使用的是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 TestBaseTestFixturesetUp From DerivedTestSetup From TestBaseSetup From DerivedTestDID a TestTearDown From DerivedTestTearDown From TestBaseTestFixtureTearDown Down From DerivedTestTestFixtureTearDown From TestBase
我能够使用ReSharper 5 beta和Nunit GUI v 2.5.3.9345(32位)测试输出
编辑在工作中,ReSharper 4.5中的测试运行程序无法正常运行,但是使用相应的NUnit.exe / NUnit-86.exe在x86和x64中运行内置测试项目可以生成有效的输出.
总结以上是内存溢出为你收集整理的c# – NUnit不服从属性继承全部内容,希望文章能够帮你解决c# – NUnit不服从属性继承所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)