【问题标题】:TestNG run the test several times conditionallyTestNG 有条件地运行测试几次
【发布时间】:2020-06-03 06:41:25
【问题描述】:

我想在 Table.getTables() 第一次返回应包含 20 个项目的表列表时运行 2 次(或更多)以下的测试,但是当第二次运行测试时它不会返回任何项目。所以,我想检查它是否是第一次运行,然后检查它是否有 20 个项目,如果是第二次运行,我想检查它是否不包含任何项目。我不认为 invocationCount 对我有用。请看下文。谢谢

Java 8 和 TestNG 6.14。


    //Run this test twice 
    @Test
    public void repeatTest() {
        List<String> tables = Table.getTables();
        //if it is 1st run then check this
        Assert.assertEquals(tables.size(), 20); 

        //if it is second run then check this 
        Assert.assertEquals(tables.size(), 0); 
    }

【问题讨论】:

    标签: java unit-testing testing testng


    【解决方案1】:

    你可以调用两次:

    @Test
    public void repeatTest() {
        List<String> firstList = Table.getTables();
        //if it is 1st run then check this
        Assert.assertEquals(firstList.size(), 20); 
    
        List<String> secondList = Table.getTables();
        //if it is second run then check this 
        Assert.assertEquals(secondList.size(), 0); 
    }
    

    【讨论】:

      猜你喜欢
      • 2023-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-04
      • 1970-01-01
      • 1970-01-01
      • 2021-09-30
      • 1970-01-01
      相关资源
      最近更新 更多