简体   繁体   English

使用InstrumentTest进行自动调用意图的活动

[英]Using InstrumentTest for an Activity which calls an Intent automatically

I am developing an Android app which uses Skobbler SDK(AKA skmaps). 我正在开发一个使用Skobbler SDK(AKA skmaps)的Android应用。 I am using InstrumentationTestRunner in order to tess my Activities. 我正在使用InstrumentationTestRunner来测试我的活动。 I have got two test classes extending ActivityInstrumentationTestCase2<MyActivity> . 我有两个扩展ActivityInstrumentationTestCase2<MyActivity>测试类。 But my first tested activity(MainActivity) already calls an Intent in order to start a second activity(MapActivity). 但是我的第一个测试活动(MainActivity)已经调用了一个Intent以便启动第二个活动(MapActivity)。 So it's a kind of SplashActivity. 因此,这是一种SplashActivity。 The test of MainActivity runs into an endless loop after testPreconditions() . testPreconditions()之后,MainActivity的测试陷入了一个无限循环。 If I remove the Intent from the MainActivity, then the test keeps on running. 如果我从MainActivity中删除了Intent,则测试将继续运行。 So how can I test an Activity with it's lifecycles if it calls an Intent without running into the endless loop? 那么,如果活动调用了一个Intent而又没有陷入无限循环,该如何用其生命周期测试活动呢?

Regards unlimited101 关于无限101

The problem was that InstrumentationTestRunner execute the activity tests in a non-deterministic order. 问题是InstrumentationTestRunner以不确定的顺序执行活动测试。 So sometimes the second activity was tested before the first activity. 因此,有时第二项活动要在第一种活动之前进行测试。 And due to loops which wait for results of the first activity, the second one was fallen into an endless loop. 由于循环等待第一个活动的结果,第二个活动陷入了一个无休止的循环。 Building test suites solves this problem. 构建测试套件可以解决此问题。 Because there you can specify the order in which the activities are tested. 因为在那里,您可以指定测试活动的顺序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM