TDH*_*DHM 2 java testng selenium-webdriver
我在我的代码中使用TestNG软断言.
public class AssertionTest{
private SoftAssert softAssert = new SoftAssert();
@Test(enabled = true)
public void testSoftAssertion(){
softAssert.assertTrue(false);
softAssert.assertTrue(true);
softAssert.assertEquals("India", "US");
softAssert.assertAll();
}
}
Run Code Online (Sandbox Code Playgroud)
当测试执行完成测试失败(如预期)但结果不提供详细信息,而是提供如下信息,这无助于理解哪个断言失败.
FAILED: testSoftAssertion
java.lang.AssertionError: The following asserts failed:
null, null
Run Code Online (Sandbox Code Playgroud)
我期待输出有助于理解结果的东西(这种类型的输出是在我们使用硬断言时产生的,即与Assert类一起使用).
FAILED: testSoftAssertion
java.lang.AssertionError: The following asserts failed:
expected [true] but found [false]
expected [India] but found [US]
Run Code Online (Sandbox Code Playgroud)
这是已知的TestNG软断言的缺陷/缺点还是有些东西,我遗漏了?
Mru*_*sar 10
您需要在断言时提供失败消息,然后它才会在报告中占用.请考虑以下代码段:
import org.testng.annotations.Test;
import org.testng.asserts.SoftAssert;
public class SoftAsert
{
@Test
public void test()
{
SoftAssert asert=new SoftAssert();
asert.assertEquals(false, true,"failed");
asert.assertEquals(0, 1,"brokedown");
asert.assertAll();
}
}
Run Code Online (Sandbox Code Playgroud)
输出:
FAILED: test
java.lang.AssertionError: The following asserts failed:
failed, brokedown
Run Code Online (Sandbox Code Playgroud)
这就是软断言的工作原理.目的是在出现故障时显示错误消息.如果这有帮助,请告诉我.
| 归档时间: |
|
| 查看次数: |
7694 次 |
| 最近记录: |