简体   繁体   English

如何在不同的前提条件下运行相同的nunit测试? (固定装置)

[英]How to run the same nunit tests with different preconditions? (fixtures)

I have set of tests and have to run it with two different SetUp in base class. 我有一组测试,并且必须在基类中使用两个不同的SetUp运行它。

Here is screenshot 这是截图 http://screencast.com/t/G150W2P4o

How can I improve it? 我该如何改善?

Create a single, parameterized test fixture. 创建一个参数化的测试夹具。 Pass in information about which setup (probably OneTimeSetUp) should be used to each instance of the fixture. 将有关应使用哪种设置(可能是OneTimeSetUp)的信息传递给灯具的每个实例。 The information will have to be constant values like strings so that it can be used as an argument to the attribute. 信息必须是常量值(例如字符串),以便可以用作属性的参数。

For example... 例如...

   [TestFixture("setup1", 5)]
   [TestFixture("setup2", 9)]
   public class MyTestFixture
   {
      public MyTestFixture(string setup, int counter)
      {
         // You can save the arguments, or do something 
         // with them and save the result in instance members
      }

      [Test]
      public void SomeTest()
      {
         // Do what you need to do, using the arguments
      }
   }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM