0

I have a test that runs multiple times using a data-provider and it looks something like:

@DataProvider(name="data-provider-carmakers")
public Object[][] dataProviderCarMakers() {
    return new Object[][] {
        {CarMaker.Ford},
        {CarMaker.Chevrolet},
        {CarMaker.Renault},
        {CarMaker.Porsche}
    };
}

@Test(  dataProvider = "data-provider-carmakers",
        retryAnalyzer = TestRetry.class)
public void validateCarMakerHasElectricModelsLoaded(CarMaker carMaker) {

    validatecarMakerContainsElectricModelsLoadedInDB(carMaker);
}


In another test, I have a dependency to the first:

@Test(  dependsOnMethods = { "validateCarMakerHasElectricModelsLoaded" })
public void validateChevroletElectricModelsPowerEfficiency() {

    List<CarModel> electricCarModels = getChevroletCarModels(fuelType.Electric);
    validatePowerEfficiency(electricCarModels);
}


(I know the test doesn't make a lot of sense, in reality the code is far more complex that this and data-provider has far more data, but for the sake of clarity I just went with this example).

So I want to run validateChevroletElectricModelsPowerEfficiency() only if validateCarMakerHasElectricModelsLoaded()[CarMaker.Chevrolet] was successful.

How the code is now, if the first test runs successful for Chevrolet, but fails for Renault, the second test won't run. Is there a way to make a dependency to just one set of data of a test?

Rodrigo Vaamonde
  • 463
  • 1
  • 6
  • 23
  • 1
    you can implement `TestListener` and add some logic in `onTestFailed` for example – Vault23 Nov 26 '19 at 12:56
  • Yes, I was thinking on doing something like that, but then I would need a conditional for every test for every parameter and could look a bit ugly and hard to maintain. I was hoping there was an option I have missed to do the dependency of a specific run of a test, but I think I'm asking for too much. Thanks for the suggestion though, it's not a bad idea. – Rodrigo Vaamonde Nov 26 '19 at 13:59

0 Answers0