代码之家  ›  专栏  ›  技术社区  ›  Andy Johnson

以编程方式跳过nunit测试

  •  37
  • Andy Johnson  · 技术社区  · 15 年前

    我这样做的动机是,我有一些测试在某些情况下不适用,但在测试(或者可能是设备)开始运行之前,这是无法确定的。

    显然在这种情况下,我可以从测试中返回并允许它成功,但是(a)这似乎是错误的,(b)我想知道测试被跳过了。

    我知道[Ignore]属性,但这是在中编译的。我正在寻找一个运行时,程序等效。类似于:

    if (testNotApplicable)
        throw new NUnit.Framework.IgnoreTest("Not applicable");
    

    2 回复  |  直到 9 年前
        1
  •  40
  •   AdaTheDev    15 年前
    Assert.Ignore();
    

    特别是你想要的,尽管也有:

    Assert.Inconclusive();
    
        2
  •  0
  •   Giannis Grivas    9 年前

    我有一个 TestInit() TestInitialize 方法,条件如下:

        //This flag is the most important.False means we want to just ignore that tests
        if (!RunFullTests)
            Assert.Inconclusive();
    

    运行测试

    当有集成测试时,我使用这个。