我目前正在Android中构建一个应用程序,并使用Robotium进行功能测试(顺便说一下,不要在没有Android 1.6的情况下使用Robotium,这太麻烦了).
其中一些测试有随机的失败倾向,主要是Robotium缺少文本字段,或超时,而不是阅读文本.我正在尝试使用@FlakyTest注释,因此它们会在抛出失败的测试错误之前运行两到三次.但是,注释不起作用,测试在失败后不会重新运行.
以下是我使用注释的方法:
public class ClassName extends ActivityInstrumentationTestCase2<HomeActivity>{
@LargeTest
@FlakyTest(tolerance=3)
public void testMethod(){
//Here I run my roboitium scripts.
}
}
Run Code Online (Sandbox Code Playgroud)
然后我从命令行运行它:
adb shell am instrument -w com.jayway.test/android.test.InstrumentationTestRunner
eclipse和测试的命令行执行都没有考虑到片状测试注释.有没有人看到我试图申请的错误@FlakyTest?
我看不出您使用注释有任何问题@FlakyTest。
我整理了一个快速测试用例来测试 @FlakyTest 和 Robotium (v2.2):
public class FlakyTestCase extends ActivityInstrumentationTestCase2<Main> {
private static int count = 0;
private Solo solo;
public FlakyTestCase() {
super("com.stackoverflow.example", Main.class);
}
@Override
public void setUp() throws Exception {
solo = new Solo(getInstrumentation(), getActivity());
}
@LargeTest
@FlakyTest(tolerance=3)
public void testFlaky(){
Log.e("FlakeyTestCase", "Execution Count:" + ++count);
solo.assertCurrentActivity(null,Main.class);
solo.clickOnText("Doesn't Exist");
Log.e("FlakeyTestCase", "Shouldn't make it here");
}
}
Run Code Online (Sandbox Code Playgroud)
LogCat 显示以下消息:
Execution Count: 1
Execution Count: 2
Execution Count: 3
Run Code Online (Sandbox Code Playgroud)
所以@FlakyTest注释肯定被调用了。测试的(最终)失败结果如下:
junit.framework.AssertionFailedError: The text: Doesn't Exist is not found!
Run Code Online (Sandbox Code Playgroud)
并且该消息"Shouldn't make it here"从未被记录。
据我所知,您如何声明注释或@FlakyTestRobotium v2.2 没有任何问题。
也许您的测试代码的另一部分有问题?
| 归档时间: |
|
| 查看次数: |
4232 次 |
| 最近记录: |