在用户名和密码字段中使用Junit 5进行参数化测试

问题描述

我正在编写一个测试框架,我想使用Junit 5在“用户名”和“密码”字段中添加参数化测试。告诉我如何在我的例子中做到这一点 请告诉我如何用不同的值代替“ [email protected]”和“ 123456789”

enter image description here

解决方法

有几种提供不同参数源的方法,该方法显示了CsvSource用于为测试提供用户对密码:

public class TestWithParams
{
    @ParameterizedTest
    @CsvSource({
        "[email protected],abc123","[email protected],xyz789"
    })
    void testWithLogin(String user,String password) {
        System.out.println("testWithLogin user="+user+" pass="+password);
    }
}

运行时将打印:

testWithLogin [email protected] pass=abc123
testWithLogin [email protected] pass=xyz789
,

enter image description here

比我想象的要容易

 @ParameterizedTest
@CsvSource({"awdwds@@mail.ru,1234","[email protected],987456","login.mail.com,12345 ",".,/,[email protected],123456"})
public void clickLoginTest(String login,String pass) {
    String acc = "Warning: No match for E-Mail Address and/or Password.";
    mainPage
            .goTo()
            .clickLogin();
    loginPage.logIntoAccount(login,pass);
    String textWrongLogIn = loginPage.getTextWrongLogIn();
    Assertions.assertEquals(acc,textWrongLogIn);
}