gpt4 book ai didi

android - 现有的 Android UI 测试在切换到 AndroidJUnitRunner 后停止工作

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:15:15 25 4
gpt4 key购买 nike

我们围绕相机功能进行了一些 UI 测试,在我们从 InstrumentationTestRunner 切换到 AndroidJUnitRunner 作为迁移到 Espresso/JUnit4 的一部分之后,我们可以当我们调用 getActivity() 时,由于频繁出现 RuntimeException,不再可靠地运行我们现有的测试:

java.lang.RuntimeException: Could not launch intent Intent { flg=0x14000000 cmp=com.cookbrite.dev/com.cookbrite.ui.ReceiptCaptureActivity (has extras) } within 45 seconds. Perhaps the main thread has not gone idle within a reasonable amount of time? There could be an animation or something constantly repainting the screen. Or the activity is doing network calls on creation? See the threaddump logs. For your reference the last time the event queue was idle before your activity launch request was 1434471981236 and now the last time the queue went idle was: 1434471981236. If these numbers are the same your activity might be hogging the event queue.
at android.support.test.runner.MonitoringInstrumentation.startActivitySync(MonitoringInstrumentation.java:315)
at android.test.InstrumentationTestCase.launchActivityWithIntent(InstrumentationTestCase.java:119)
at android.test.ActivityInstrumentationTestCase2.getActivity(ActivityInstrumentationTestCase2.java:106)
at com.cookbrite.step2_functional.ui.receipt.ReceiptCaptureTest.getActivity(ReceiptCaptureTest.java:43)

为了更好的可读性,这是引用 RuntimeException 的错误消息:

Could not launch intent Intent { flg=0x14000000 cmp=com.cookbrite.dev/com.cookbrite.ui.ReceiptCaptureActivity (has extras) } within 45 seconds. Perhaps the main thread has not gone idle within a reasonable amount of time? There could be an animation or something constantly repainting the screen. Or the activity is doing network calls on creation? See the threaddump logs. For your reference the last time the event queue was idle before your activity launch request was 1434471981236 and now the last time the queue went idle was: 1434471981236. If these numbers are the same your activity might be hogging the event queue.

我们现有的测试使用 Robotium。尝试使用 Espresso 编写相同的测试产生了类似的错误,这可能是由于相机预览不断更新 UI。然而,即使将预览设置为 INVISIBLE,我们仍然会遇到 Espresso 的这个问题。

关于如何解决这个问题的任何想法/指示(除了返回 InstrumentationTestRunner)?

最佳答案

错误输出表明测试类扩展了 ActivityInstrumentationTestCase2。我不确定迁移到新的 ActivityTestRule 是否会对您的情况产生任何影响,但值得快速检查一下。将其放在答案而不是评论中以包含示例代码:

@RunWith(AndroidJUnit4.class)
public class ReceiptCaptureTestNew {
private ReceiptCaptureActivity mReceiptCaptureActivity;

@Rule
public ActivityTestRule<mReceiptCaptureActivity> mActivityRule =
new ActivityTestRule<>(mReceiptCaptureActivity.class);

@Before
public void setUp() throws Exception {
mReceiptCaptureActivity = mActivityRule.getActivity();
}

@After
public void tearDown() throws Exception {
// Call finish() on all activities in @After to avoid exceptions in
// later calls to getActivity() in subsequent tests
mReceiptCaptureActivity.finish();
}

@Test
public void testPreconditions() {
assertNotNull(mReceiptCaptureActivity);
assertThat(mReceiptCaptureActivity.hasWindowFocus(), is(true));
}
}

关于android - 现有的 Android UI 测试在切换到 AndroidJUnitRunner 后停止工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30876109/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com