【问题标题】:How to check that activity displays dialog during android unit testing如何在android单元测试期间检查活动是否显示对话框
【发布时间】:2010-09-23 12:19:04
【问题描述】:

我想使用 JUnit 为我的 android 应用程序编写测试用例。 我遇到了一些问题。

是否可以检查活动当前是否显示一些对话框? 这是我的测试应用程序的一小部分:

    ...
    Instrumentation instr = getInstrumentation();
    monitor = instr.addMonitor(MainActivity.class.getName(), null, false);
    /* Click on login button */
    TouchUtils.clickView(this, mLoginButton);
    /* wait MainActivity */
    mMainActivity = instr.waitForMonitorWithTimeout(monitor, 3);
    assertNotNull(mMainActivity); 
    /* Here a want to check that progress dialog displayed on mMainActivity */

提前致谢!

【问题讨论】:

    标签: android unit-testing testing junit


    【解决方案1】:

    看看 Robotium
    '一个开源测试框架,旨在使 Android 应用程序的自动黑盒测试比使用 Android 检测工具更快、更容易开箱即用的测试。'

    主页: http://www.robotium.org/
    来源: http://github.com/jayway/robotium

    请注意,Robotium 项目由我工作的公司维护

    【讨论】:

    • 乔纳斯,谢谢!我尝试使用您的框架,它很棒!但不幸的是,我们公司的政策禁止在我们的测试中使用任何第 3 方组件 :(
    • 查看 Robotium 的代码,它是开源的。也许你可以在那里找到可以帮助你的东西。
    • Jonas,是否可以使用 robotium 检查当前活动中是否出现了一些 toast?
    • 嗨,Evgeny。尝试使用 searchText,但请注意它区分大小写。如果您有更多关于 robots 的问题,请查看 Robotium Google Group groups.google.com/group/robotium-developers
    猜你喜欢
    • 2012-11-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-01
    • 1970-01-01
    • 2011-05-02
    • 1970-01-01
    • 2011-01-29
    • 1970-01-01
    相关资源
    最近更新 更多