【发布时间】:2018-10-03 13:33:30
【问题描述】:
我正在尝试使用 TestNG(当然还有 dataprovider 注释)执行数据驱动测试。
我的场景是这样的......
-
使用 dataProvider 拥有一个 2 暗淡的数组。 (我正在使用它从 Excel 中读取,但为了问题的简洁而避免使用它)。
@DataProvider(name = "featureTest") public Object[][] dataSets() throws Exception { return new Object[][] { {"TC_01", "testuser_1", "Test@123", "ABC Street", "123-456-7899" }, { "TC_02", "testuser_1", "Test@123", "PQR Street", "222-456-7899" } }; } -
@Test 方法中,根据功能流程有几种方法-
@Test(dataProvider = "featureTest") public void executeTest(String... data) throws Exception { try{ feature_1.execute(data); feature_2.execute(data); feature_3.execute(data); feature_4.execute(data); } catch(Exception e){ log.error("Error has occured"); } }
现在我的主要问题是功能错误可能发生在我在@Test 中指定的这 4 (n) 个方法中的任何地方。
如果任何方法出现异常,我需要“跳过”特定数据集并继续下一个。 例如:TC_01执行过程中,feature_2.execute()发生异常,不应该执行feature_3和feature_4方法。
注意: 我尝试使用@BeforeMethod、@AfterMethod 处理它,但它仍然会通过我想要避免的不需要的方法。
提前感谢您的帮助/输入 && 为这个冗长的问题道歉,虽然是一个相对简单的概念来解释!!!
【问题讨论】:
-
请注意,我已经尝试过使用 SkipException (TestNG),但是在 TC_01 失败时,它会跳过 TC_02 和其他后续数据集。此外,它也不能达到跳过上述方法的目的。
-
你的执行方法中有什么?除非你在那里捕捉到你的异常,否则你所说的是不可能的,尽管有 feature_2.execute(data);抛出异常,feature_3 被执行。