Following are the two snippets for negative test case. Which is the right way to assert status 200(to mark it as fail) or 401(expected in negative test case) in test cases ?
@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);
}
You need to specify the expected code in the assertEquals method. In your case, if the status code is 401, then your test should pass else test should be fail. So, you can assert as below.
@Test(priority=2)
public void negativeTestCase() throws Exception{
int status=asset.postRequest("", "", "");
Assert.assertEquals(status, 401);
}