9

有没有人使用 Robotium 或 Calculon 来测试 Android 应用程序?它们有用吗?有什么更好的推荐吗?

4

1 回答 1

7

我会选择 Robotium,因为 Calculon 仍处于早期阶段。这是Calculon作者的评论:

好吧,目前它只是我从另一个项目中提取的一堆源文件......请注意,这个库仍然是一个非常早期的原型。它的 API 可能会改变。资源

我今天玩过 Robotium,它绝对让编写功能测试变得有趣。为了给您一个想法,以下是 API 中的一些方法亮点:

  • 点击按钮,点击文本
  • 输入文本
  • getCurrentButtons、getCurrentEditTexts、getCurrentImageViews、getCurrentSpinners、getCurrentTextViews
  • pressMenuItem, pressSpinnerItem
  • 搜索文本、搜索编辑文本、搜索按钮

以下是入门指南中的代码示例:

  public void testTextIsSaved() throws Exception {
    solo.clickOnText("Other");
    solo.clickOnButton("Edit");
    assertTrue(solo.searchText("Edit Window"));
    solo.enterText(1, "Some text for testing purposes")
    solo.clickOnButton("Save");
    assertTrue(solo.searchText("Changes have been made successfully"));
    solo.clickOnButton("Ok");
    assertTrue(solo.searchText("Some text for testing purposes"));}

如果您要编写ActivityInstrumentationTestCase2类,请务必尝试一下。查看入门指南以获取说明。

于 2010-02-21T17:05:40.813 回答