在 TestNG 中断言测试用例的正确方法是什么?
Which is the right way to assert test cases in TestNG?
以下是否定测试用例的两个片段。
在测试用例中断言状态 200(将其标记为失败)或 401(在负面测试用例中预期)的正确方法是什么?
@Test(priority=2)
public void negativeTestCase() throws Exception{
int status=asset.postRequest("", "", "");
Assert.assertEquals(status, 200);
}
@Test(priority=2)
public void negativeTestCase() throws Exception{
int status=asset.postRequest("", "", "");
Assert.assertEquals(status, 401);
}
您需要在 assertEquals 方法中指定预期的代码。在您的情况下,如果状态代码为 401,那么您的测试应该通过,否则测试应该失败。所以,你可以断言如下。
@Test(priority=2)
public void negativeTestCase() throws Exception{
int status=asset.postRequest("", "", "");
Assert.assertEquals(status, 401);
}
以下是否定测试用例的两个片段。 在测试用例中断言状态 200(将其标记为失败)或 401(在负面测试用例中预期)的正确方法是什么?
@Test(priority=2)
public void negativeTestCase() throws Exception{
int status=asset.postRequest("", "", "");
Assert.assertEquals(status, 200);
}
@Test(priority=2)
public void negativeTestCase() throws Exception{
int status=asset.postRequest("", "", "");
Assert.assertEquals(status, 401);
}
您需要在 assertEquals 方法中指定预期的代码。在您的情况下,如果状态代码为 401,那么您的测试应该通过,否则测试应该失败。所以,你可以断言如下。
@Test(priority=2)
public void negativeTestCase() throws Exception{
int status=asset.postRequest("", "", "");
Assert.assertEquals(status, 401);
}