mercredi 13 mai 2020

Passing lambdas as testng parameters using DataProvider?

I was wondering if there is a way to pass lambdas from testng's data providers. So I want to do something like the following:

@DataProvider(name="checkProvider")
public Object[][] checkProvider() {
    return new Object[][]{
        "Some string to test", (String string) -> string.length() > 2 //A predicate on how to test response
    }
}

And after that have some test like so

@Test(dataProvider="checkProvider")
public void testsomething(String s, Predicate<String> checker) {
    //so some operation on s to get a string I want to check
    Assert.assertTrue(checker.check(someString));
}

Right now I'm not able to do this as I get Target type of lambda conversion must be an interface. Does anyone have an idea on how to do this or even an alternative would be good so I could achieve the desired functionality.

Aucun commentaire:

Enregistrer un commentaire