4520 shaares
1 résultat
taggé
test-paramétré
Exemple d'utilisation des tests paramétrés en TestNG avec les DataProvider :
import static org.assertj.core.Asserstions.assertThat;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
public class ExempleTest {
private PrimeNumberChecker primeNumberChecker = new PrimeNumberChecker();
@DataProvider(name = "test1")
static Object[][] primeNumbers() {
return new Object[][] {{2, true}, {6, false}, {19, true}, {22, false}, {23, true}};
}
// This test will run 5 times since we have 5 parameters defined
@Test(dataProvider = "test1")
void testPrimeNumberChecker(Integer inputNumber, Boolean expectedResult) {
assertThat(primeNumberChecker.validate(inputNumber)).isEqualTo(expectedResult);
}
}