Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#NUnit-&x27;依赖于方法';来自TestNG_C#_Nunit - Fatal编程技术网

C#NUnit-&x27;依赖于方法';来自TestNG

C#NUnit-&x27;依赖于方法';来自TestNG,c#,nunit,C#,Nunit,使用TestNG,我们具有“dependsOnMethods”功能,该功能可检查另一个TC是否已通过以执行当前TC,如果失败,则不会执行,除非您添加alwaysRun标签,如下所示: @Test(dependsOnMethods={ "testMethod2" }, alwaysRun=true) public void testMethod1() { System.out.println("testMethod1"); } @Test public void testMethod2(

使用TestNG,我们具有“dependsOnMethods”功能,该功能可检查另一个TC是否已通过以执行当前TC,如果失败,则不会执行,除非您添加alwaysRun标签,如下所示:

@Test(dependsOnMethods={ "testMethod2" }, alwaysRun=true)
public void testMethod1() {
    System.out.println("testMethod1");
}

@Test
public void testMethod2() {
    System.out.println("testMethod2");
    int result = 3;
    Assert.assertEquals(result, 2);
}

使用NUnit有没有办法达到同样的行为?

使用NUnit自己的设施,没有办法做到这一点。关于添加这种依赖关系已经有很多讨论,但它还不存在。也许TestNG是一个很好的未来属性模型

目前,您所能做的就是在NUnit中排序测试。因此,如果您给出
testMethod2
属性[Order(1)],它将在夹具中的任何其他测试之前运行。这有一些局限性:

  • 排序与开始测试有关,而不是等待测试完成。在并行环境中,两个测试仍然可以一起运行。因此,要使用此解决方案,您不应该并行运行夹具中的测试。当然,固定装置仍然可以相互平行运行

  • 没有规定
    testMethod2
    必须通过才能运行
    testMethod1
    。您可以通过在
    testMethod2
    中设置一个实例字段并在
    testMethod1
    中对其进行测试来自行处理。我可能会使用
    假设对其进行测试。假设
    ,以便在测试方法2失败的情况下,测试方法1不会显示为警告或错误