我写了ff。行为测试。编写等待31分钟以覆盖到期场景的测试是否可以接受并且是良好的做法?
public class ExpiredTokenBehaviorTestCase extends ActivityInstrumentationTestCase2<ResetPasswordActivity> {
protected Solo solo;
public final static int TOKEN_EXPIRATION_MINS = 31 * 1000 * 60; // 31 minutes, sanity check, can't do math
public ExpiredTokenBehaviorTestCase() {
super(ResetPasswordActivity.class);
}
@Override
protected void setUp() throws Exception {
solo = new Solo(getInstrumentation(), getActivity());
}
@Override
protected void tearDown() throws Exception {
solo.finishOpenedActivities();
}
/**
* Expired
*/
public void testExpiredPassword() {
solo.typeText(0, "+639224424166"); // type in mobile number to send the verification code
solo.clickOnButton("Next >"); // click next
if (solo.waitForActivity(VerificationActivity.class)) {
solo.typeText(0, "ab2f1de"); // valid code
solo.sleep(TOKEN_EXPIRATION_MINS); // wait for token to expire
solo.clickOnButton("Next >"); // now click on next
solo.waitForText("Verification code expired"); // should show the code expired
}
}
}
最佳答案
自动化测试应尽可能快地运行。它们运行得越快,运行它们就越便宜。这样,您可以让它们频繁运行,并为您提供关于成功和失败的快速反馈。快速执行的测试还可以使连续集成运行的时间短且易于管理,这是宝贵的收获。
31分钟太长了,测试无法给出反馈。相反,您应该旨在能够控制测试中令牌的到期时间,并生成可以立即到期的令牌,以便您可以立即测试到期方案,而不必完全等待。