英文:
parameterized tests using Junit 5 in the "username" and "password" fields
问题
我正在编写一个测试框架,希望在 "username" 和 "password" 字段中使用 Junit 5 添加参数化测试。请告诉我如何在我的示例中执行此操作。
请告诉我如何替换不同的值,而不是 "awdawd@mail.ru" 和 "123456789"。
英文:
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"
答案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
英文:
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);
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论