gpt4 book ai didi

java - 将 Robotium 中的 testMethod() 拆分为多个 testMethods() - Android JUnit 测试用例

转载 作者:行者123 更新时间:2023-12-01 13:23:32 27 4
gpt4 key购买 nike

我已经能够自动化我的应用程序的整个流程。我有一个 testMethod() 来处理流程的自动化。我想将这个单一方法拆分为其他几个方法,以提高代码的可读性。但是,我在这里担心,如果我将测试方法拆分为其他方法,首先,必须注意执行顺序,更重要的是,一旦一个测试成功运行并关闭该 Activity ,我的 Activity 就会终止,从而进行以下测试失败。

我该如何解决这个问题?有什么办法可以将我的 testMethod 分成几个 testMethods() 而不关闭 Activity ?

包括我当前的 testMethod()

public void testApp() throws BiffException, IOException {

Excel rd= new Excel();
rd.read();

user = rd.getUser();
pass = rd.getPass();
bp = rd.getBill();
rdc = rd.getRdc();
pr = rd.getPr();

// Login to the application
solo.enterText(0,user); // Enter user name
solo.sleep(1000);
solo.enterText(1,"xxx"); //some random password
solo.sleep(1000);
solo.clickOnButton(1); // Try Login! (bad login)
solo.sleep(5000);
solo.clickOnButton(0);
solo.sleep(2500);
solo.enterText(1,pass); // Enter Password (authentic password)
solo.sleep(2500);
solo.clickOnButton(1); // Try Login! (Valid login)
solo.sleep(10000);

// MFA
solo.clickOnButton(0); // choose Text Me (xxx-xxx-3576)
solo.sleep(20000);

//Account Summary
solo.clickOnButton(0);
solo.sleep(15000);

//Account History
if(solo.searchText(ch)){
solo.clickOnText(ch);
solo.sleep(10000);
}
else if (solo.searchText(sv)){
solo.clickOnText(sv);
solo.sleep(10000);
}
else{
solo.clickInList(1);
}

//Transfers
solo.clickOnMenuItem("Transfers");
solo.sleep(10000);
solo.clickOnText("From"); //choose 'From' account
solo.sleep(5000);
solo.clickInList(1); //click on first available account
solo.sleep(5000);
solo.clickOnText("To"); //choose 'To' account
solo.sleep(5000);
solo.clickInList(2); //click on second available account
solo.sleep(5000);
solo.clickOnText("Amount"); //Amount to transfer
solo.sleep(10000);
solo.typeText(0,"10.00"); //enter amount for over limit transfer
solo.sleep(5000);
solo.clickOnButton("Transfer");
solo.sleep(10000);
solo.clickOnButton(0);
solo.sleep(5000);

//Bill Pay
if(bp.equalsIgnoreCase(flag)){
solo.clickOnMenuItem("Bills");
solo.sleep(10000);
}

//RDC
if (rdc.equalsIgnoreCase(flag)) {
solo.clickOnMenuItem("Deposits");
solo.sleep(10000);
//solo.scrollUp();
//solo.sleep(10000);
}

//PR
if(pr.equalsIgnoreCase(flag)){
solo.clickOnMenuItem("Rewards");
solo.sleep(1000);
}

//More
solo.clickOnMenuItem("More");
solo.sleep(10000);

//Call
solo.clickOnButton(0);
solo.sleep(10000);
solo.clickOnButton(0); //cancel
solo.sleep(10000);

//Logout
solo.clickOnImage(0); //click on Logout
solo.sleep(5000);
solo.clickOnButton(1); //to cancel the logout
solo.sleep(5000);
solo.clickOnImage(0); //click on Logout
solo.sleep(10000);
solo.clickOnButton(0); //Yes
solo.sleep(10000);
}

期待您的帮助!

提前致谢!

最佳答案

你可以这样做:

public void testApp() throws BiffException, IOException {
login();
...
logout();
}

private void login(){
// Login to the application
solo.enterText(0,user); // Enter user name
solo.sleep(1000);
solo.enterText(1,"xxx"); //some random password
solo.sleep(1000);
solo.clickOnButton(1); // Try Login! (bad login)
solo.sleep(5000);
solo.clickOnButton(0);
solo.sleep(2500);
solo.enterText(1,pass); // Enter Password (authentic password)
solo.sleep(2500);
solo.clickOnButton(1); // Try Login! (Valid login)
solo.sleep(10000);
}

private void logout(){
solo.clickOnImage(0); //click on Logout
solo.sleep(5000);
solo.clickOnButton(1); //to cancel the logout
solo.sleep(5000);
solo.clickOnImage(0); //click on Logout
solo.sleep(10000);
solo.clickOnButton(0); //Yes
solo.sleep(10000);
}

因此,在测试过程中,所有以 test 开头的方法(例如 testMethod1、testApp 等)都会被调用,并且它们会调用其他子方法。

无论如何都不可能恢复应用程序以前的状态。

另一个解决方案是您在前提条件下编写测试:例如,所有测试都需要应用程序登录。

关于java - 将 Robotium 中的 testMethod() 拆分为多个 testMethods() - Android JUnit 测试用例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21907654/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com