Java 我们可以在一个断言中使用多个TestNG断言吗
我是自动化测试的新手,这里我正在使用断言检查测试中字段的可用性。因此,如果我们可以将所有字段合并到一个断言中,而不是使用Java 我们可以在一个断言中使用多个TestNG断言吗,java,selenium,testng,Java,Selenium,Testng,我是自动化测试的新手,这里我正在使用断言检查测试中字段的可用性。因此,如果我们可以将所有字段合并到一个断言中,而不是使用Assert,请有人帮助我。因此,无论哪个字段不符合预期,都将相应地进行报告 下面是一个例子:-- 对。这就是为什么会有SoftAssert SoftAssert-在@Test期间收集错误(不会引发异常),如果调用org.testng.asserts.SoftAssert,则在@Test结束时会引发assertAll异常,如果存在异常,测试套件将再次继续下一个@Test 研究使
Assert
,请有人帮助我。因此,无论哪个字段不符合预期,都将相应地进行报告
下面是一个例子:--
对。这就是为什么会有SoftAssert SoftAssert-在@Test期间收集错误(不会引发异常),如果调用org.testng.asserts.SoftAssert,则在@Test结束时会引发assertAll异常,如果存在异常,测试套件将再次继续下一个@Test 研究使用SoftAssert 大概是这样的:
public class SoftAsert
{
@Test
public void test()
{
SoftAssert asert=new SoftAssert();
asert.assertEquals(false, true,"failed");
asert.assertEquals(0, 1,"brokedown");
asert.assertAll();
}
}
你不想这么做。。。如果少了一个,你会失败,但不知道三个中哪一个是少的。
public class SoftAsert
{
@Test
public void test()
{
SoftAssert asert=new SoftAssert();
asert.assertEquals(false, true,"failed");
asert.assertEquals(0, 1,"brokedown");
asert.assertAll();
}
}