【问题标题】:Testng marked a test as success when it should fail当测试应该失败时,Testng 将测试标记为成功
【发布时间】:2012-01-30 06:19:48
【问题描述】:

我有如下测试代码。 test1 通过了测试,但是当我预计两者都失败时, test2 失败了。谁能解释一下为什么会这样?

@Test(dataProvider="prov")
public void test1(int x, int y){
    System.out.println("x=" + x + ", y=" + y);
    assertEquals(x + y, 3);
}

@Test(dataProvider="prov")
public void test2(int x, int y){
    System.out.println("x=" + x + ", y=" + y);
    assertEquals(x + y, 7);
}

@DataProvider
public Object[][] prov(){
    return new Object[][]{
        {1,2},
        {3,4}
    };
}

【问题讨论】:

  • 你有诊断信息 - 打印什么?
  • x=1, y=2 x=3, y=4 x=1, y=2 x=3, y=4
  • 好的,两个测试都在执行。我希望看到每个测试的两次调用,一次通过,一次失败......你确定你不只是在测试运行结果中看到每个方法的第一次调用吗?
  • 这就是问题所在。我希望这两种方法都被调用两次,并且由于每种方法都会有一次失败的调用,我希望这两种方法都会失败。但最后我得到了 test1 通过,而 test2 失败了。
  • 尝试在命令行上运行您的测试,同时使用最新版本的 TestNG。

标签: java netbeans testng dataprovider


【解决方案1】:

宾果!这是一个 netbeans 错误。在命令行中,两个测试都失败了。

立即报告错误...

【讨论】:

    猜你喜欢
    • 2020-03-26
    • 1970-01-01
    • 1970-01-01
    • 2017-02-04
    • 1970-01-01
    • 1970-01-01
    • 2012-07-12
    • 2017-12-02
    • 2011-08-04
    相关资源
    最近更新 更多