使用 JUnit 5 中的参数化测试在 “username” 和 “password” 字段中。

huangapple go评论61阅读模式
英文:

parameterized tests using Junit 5 in the "username" and "password" fields

问题

我正在编写一个测试框架,希望在 "username" 和 "password" 字段中使用 Junit 5 添加参数化测试。请告诉我如何在我的示例中执行此操作。

请告诉我如何替换不同的值,而不是 "awdawd@mail.ru" 和 "123456789"。

使用 JUnit 5 中的参数化测试在 “username” 和 “password” 字段中。

英文:

I am writing a testing framework and I want to add parameterized tests using Junit 5 in the "username" and "password" fields. tell me how to do this on my example
Please tell me how to substitute different values instead of "awdawd@mail.ru" and " 123456789"

使用 JUnit 5 中的参数化测试在 “username” 和 “password” 字段中。

答案1

得分: 1

有几种方法可以提供不同的参数来源这个示例展示了使用 CsvSource 提供用户和密码对给测试的方法

public class TestWithParams
{
    @ParameterizedTest
    @CsvSource({
        "one@two.com,abc123",
        "three@four.com,xyz789"
    })
    void testWithLogin(String user, String password) {
        System.out.println("testWithLogin user=" + user + " pass=" + password);
    }
}

运行时它会打印出

testWithLogin user=one@two.com pass=abc123
testWithLogin user=three@four.com pass=xyz789
英文:

There are several ways to supply different argument sources, this one shows CsvSource for supplying pairs of user+passwords to a test:

public class TestWithParams
{
    @ParameterizedTest
    @CsvSource({
        "one@two.com,abc123"
        ,"three@four.com,xyz789"
    })
    void testWithLogin(String user, String password) {
        System.out.println("testWithLogin user="+user+" pass="+password);
    }
}

When run it prints:

testWithLogin user=one@two.com pass=abc123
testWithLogin user=three@four.com pass=xyz789

答案2

得分: 1

![输入图像描述][1]

这比我想象的要简单

     @ParameterizedTest
    @CsvSource({"awdwds@@mail.ru,           1234",
               "!smith@gmail.com,           987456",
                "login.mail.com,            12345 ",
                ".,/,star@yandex.ru,        123456"})
    public void clickLoginTest(String login, String pass) {
        String acc = "警告:电子邮件地址和/或密码不匹配。";
        mainPage
                .goTo()
                .clickLogin();
        loginPage.logIntoAccount(login, pass);
        String textWrongLogIn = loginPage.getTextWrongLogIn();
        Assertions.assertEquals(acc, textWrongLogIn);
    }

  [1]: https://i.stack.imgur.com/sLpCG.png
英文:

使用 JUnit 5 中的参数化测试在 “username” 和 “password” 字段中。

it was easier than I thought

 @ParameterizedTest
@CsvSource({"awdwds@@mail.ru,           1234",
           "!smith@gmail.com,           987456",
            "login.mail.com,            12345 ",
            ".,/,star@yandex.ru,        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);
}

huangapple
  • 本文由 发表于 2020年8月22日 22:39:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/63537380.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定