如何在不同的前提条件下运行相同的 nunit 测试?(赛程)

Tat*_*ana 2 c# nunit

我有一组测试,必须在基类中使用两个不同的 SetUp 来运行它。

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

我该如何改进它?

Cha*_*lie 5

创建单个参数化测试夹具。传递有关应将哪个设置(可能是 OneTimeSetUp)应用于夹具的每个实例的信息。该信息必须是字符串等常量值,以便可以用作属性的参数。

例如...

   [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
      }
   }
Run Code Online (Sandbox Code Playgroud)