作为测试自动化的一部分,我想创建一些测试帐户/数据,然后将这些值提供给测试配置文件。此配置文件包含用户凭据等详细信息,需要在Espresso测试中使用。
如何使用Espresso进行此操作?
答案 0 :(得分:1)
就我而言,我已经为用户数据实现了枚举,如下所示:
public enum UserData {
testUser1("email1@email.com", "password", "Name", "Surname"),
testUser2("email2@email.com", "password", "Name", "Surname");
private String email;
private String password;
private String name;
private String surname;
UserData(final String email, final String password, final String name, final String surname) {
this.email = email;
this.password = password;
this.name = name;
this.surname = surname;
}
public String getName() {
return this.name;
}
public String getDisplayName() {
return this.name + " " + this.surname;
}
public String getPassword() {
return this.password;
}
public String getEmail() {
return this.email;
}
public String getSurname() {
return this.surname;
}
}
然后,您可以将此类导入测试类并访问任何用户数据:
import com.your.app.test.UserData;
并测试自己:
@Test
public void simpleTest() {
onView(withId(R.id.edit_text_field))
.perform(typeText(UserData.testUser1.getEmail()), closeSoftKeyboard());
//do other stuff
}