samedi 17 février 2018

Testng - Skip dependent tests for only failed data sets

I am attempting to modify my dependent tests so they are ran in a specific way and have yet find a way possible. For instance, say I have the following two tests and the defined data provider:

@Dataprovider(name = "apiResponses")
Public void queryApi(){
  return getApiResponses().entrySet().stream().map(response -> new Object[]{response.getKey(), response.getValue()}).toArray(Object[][]::new);
}

@Test(dataprovider = "apiResponses")
Public void validateApiResponse(Object apiRequest, Object apiResponse){
  if(apiResponse.statusCode != 200){
    Assert.fail("Api Response must be that of a 200 to continue testing");
  }
}

@Test(dataprovider = "apiResponses", dependsOnMethod="validateApiResponse")
Public void validateResponseContent(Object apiRequest, Object apiResponse){
  //The following method contains the necessary assertions for validating api repsonse content
  validateApiResponseData(apiResponse); 
}

Say I have 100 api requests I want to validate, with the above, if a single one of those 100 requests were to return a status code of anything other than 200, then validateResponseContent would be skipped for all 100. What I'm attempting to achieve is that the dependent tests would be skipped for only the api responses that were to return without a status code of 200 and for all tests to be ran for responses that returned WITH a status code of 200.

Aucun commentaire:

Enregistrer un commentaire