有没有人使用 Robotium 或 Calculon 来测试 Android 应用程序?它们有用吗?有什么更好的建议吗?
最佳答案
我会选择 Robotium,因为 Calculon 仍处于早期阶段。这是 Calculon 作者的评论:
Well, currently it’s just a bunch of source files which I pulled out of another project...Note that this library is still a very early prototype. Its API will probably change. Source
我今天玩过 Robotium,它确实让编写功能测试变得有趣。为了给您一个想法,以下是 API 中的一些方法亮点:
- 点击按钮,点击文本
- 输入文本
- getCurrentButtons、getCurrentEditTexts、getCurrentImageViews、getCurrentSpinners、getCurrentTextViews
- 按下菜单项,按下微调器项
- 搜索文本、搜索编辑文本、搜索按钮
这是入门指南中的代码示例:
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 类,一定要试一试。查看Getting Started指导说明。
关于android - 有没有人使用 Robotium 或 Calculon 来测试 Android 应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2300122/