我正在测试从网络中获取杨树电影列表的应用程序。我的应用程序使用rxjava2,dagger2,butterknife和改造。我最近尝试将检测测试用例添加到我的应用程序中,但它失败了。
我试过使用JakeWharton的RxIdler但是没有用。有人可以帮我解决我在这里做错的事。
@RunWith(AndroidJUnit4.class)
@LargeTest
public class MoviesListingActivityAndroidTest {
@Rule
public ActivityTestRule<MoviesListingActivity> moviesListingActivityRule =
new ActivityTestRule<MoviesListingActivity>(MoviesListingActivity.class, false, true);
@Rule
public IntentsTestRule<MoviesListingActivity> intentsTestRule =
new IntentsTestRule<>(MoviesListingActivity.class);
MoviesListingActivity moviesListingActivity;
@BeforeClass
public static void setupClass() throws Exception {
RxJavaPlugins.setInitIoSchedulerHandler(Rx2Idler.create("Rxjava 2.0 Io Scheduler"));
RxJavaPlugins.setInitComputationSchedulerHandler(Rx2Idler.create("Rxjava 2.0 computation Scheduler"));
RxJavaPlugins.setInitNewThreadSchedulerHandler(Rx2Idler.create("Rxjava 2.0 new thread Scheduler"));
RxJavaPlugins.setInitSingleSchedulerHandler(Rx2Idler.create("Rxjava 2.0 single scheduler Scheduler"));
RxAndroidPlugins.setInitMainThreadSchedulerHandler(Rx2Idler.create("rxjava 2.0 mainscheduler"));
}
@Test
public void onCreateTest() throws Exception {
onView(withId(R.id.toolbar)).check(ViewAssertions.matches(IsNull.notNullValue()));
assertThat(moviesListingActivity.toolbar.getTitle(), Is.is(moviesListingActivity.getString(R.string.movie_guide)));
onView(withId(R.id.movie_details_container)).check(doesNotExist());
onView(withId(R.id.action_sort)).check(ViewAssertions.matches(IsNull.notNullValue()));
}
}
这是来自上述测试用例的堆栈跟踪。
D/TestExecutor: Adding listener android.support.test.internal.runner.listener.LogRunListener
D/TestExecutor: Adding listener android.support.test.orchestrator.instrumentationlistener.OrchestratedInstrumentationListener
Started running tests
D/TestExecutor: Adding listener android.support.test.internal.runner.listener.ActivityFinisherRunListener
I/TestRunner: run started: 1 testsI/TestRunner: started: onCreateTest(com.esoxjem.movieguide.listing.MoviesListingActivityAndroidTest)
I/MonitoringInstr: Activities that are still in CREATED to STOPPED: 0
W/ActivityTestRule: getActivityIntent() returned null using default: Intent(Intent.ACTION_MAIN)
I/ActivityTestRule: Launching activity: ComponentInfo{com.esoxjem.movieguide/com.esoxjem.movieguide.listing.MoviesListingActivity}
D/MonitoringInstr: execStartActivity(context, ibinder, ibinder, activity, intent, int, bundle
D/LifecycleMonitor: Lifecycle status change: com.esoxjem.movieguide.listing.MoviesListingActivity@e1d22 in: PRE_ON_CREATE
W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
I/AppCompatViewInflater: app:theme is now deprecated. Please move to using android:theme instead.
D/NetworkSecurityConfig: No Network Security Config specified, using platform default
I/System.out: loadpopular movies
D/OkHttp: --> GET http://api.themoviedb.org/3/discover/movie?language=en&sort_by=popularity.desc http/1.1
D/OkHttp: --> END GET
D/LifecycleMonitor: Lifecycle status change: com.esoxjem.movieguide.listing.MoviesListingActivity@e1d22 in: CREATED
D/LifecycleMonitor: Lifecycle status change: com.esoxjem.movieguide.listing.MoviesListingActivity@e1d22 in: STARTED
D/LifecycleMonitor: Lifecycle status change: com.esoxjem.movieguide.listing.MoviesListingActivity@e1d22 in: RESUMED
I/OpenGLRenderer: Initialized EGL, version 1.4
D/OpenGLRenderer: Swap behavior 1
W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
D/OpenGLRenderer: Swap behavior 0
D/EGL_emulation: eglCreateContext: 0xa2f98ce0: maj 2 min 0 rcv 2
D/EGL_emulation: eglMakeCurrent: 0xa2f98ce0: ver 2 0 (tinfo 0xa4cbcb20)
W/art: Before Android 4.1, method int android.support.v7.widget.ListViewCompat.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
D/EGL_emulation: eglMakeCurrent: 0xa2f98ce0: ver 2 0 (tinfo 0xa4cbcb20)
W/ActivityTestRule: getActivityIntent() returned null using default: Intent(Intent.ACTION_MAIN)
I/ActivityTestRule: Launching activity: ComponentInfo{com.esoxjem.movieguide/com.esoxjem.movieguide.listing.MoviesListingActivity}
D/MonitoringInstr: execStartActivity(context, ibinder, ibinder, activity, intent, int, bundle
D/LifecycleMonitor: Lifecycle status change: com.esoxjem.movieguide.listing.MoviesListingActivity@e1d22 in: PAUSED
D/LifecycleMonitor: Lifecycle status change: com.esoxjem.movieguide.listing.MoviesListingActivity@e1d22 in: RESUMED
D/OkHttp: <-- 200 OK http://api.themoviedb.org/3/discover/movie?language=en&sort_by=popularity.desc&api_key=<API_KEY> (759ms)
D/OkHttp: Access-Control-Allow-Origin: *
D/OkHttp: Access-Control-Expose-Headers: ETag, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, Retry-After
D/OkHttp: Cache-Control: public, max-age=21600
D/OkHttp: Content-Type: application/json;charset=utf-8
D/OkHttp: Date: Fri, 09 Mar 2018 03:36:14 GMT
D/OkHttp: Server: openresty
D/OkHttp: Vary: Accept-Encoding
D/OkHttp: X-RateLimit-Limit: 40
D/OkHttp: X-RateLimit-Remaining: 39
D/OkHttp: X-RateLimit-Reset: 1520566584
D/OkHttp: Connection: keep-alive
D/OkHttp: <RESULTS CAME FROM NETWORK>
D/OkHttp: <-- END HTTP (13185-byte body)
I/System.out: on movie result
I/art: Do partial code cache collection, code=28KB, data=19KB
I/art: After code cache collection, code=28KB, data=19KB
I/art: Increasing code cache capacity to 128KB
I/art: Do partial code cache collection, code=61KB, data=49KB
I/art: After code cache collection, code=55KB, data=46KB
I/art: Increasing code cache capacity to 256KB
E/THREAD_STATE: Thread[HeapTaskDaemon,5,system]
dalvik.system.VMRuntime.runHeapTasks(Native Method)
java.lang.Daemons$HeapTaskDaemon.run(Daemons.java:433)
java.lang.Thread.run(Thread.java:761)
Thread[InstrumentationConnectionThread,5,main]
android.os.MessageQueue.nativePollOnce(Native Method)
android.os.MessageQueue.next(MessageQueue.java:323)
android.os.Looper.loop(Looper.java:136)
android.os.HandlerThread.run(HandlerThread.java:61)
Thread[fifo-pool-thread-0,5,main]
java.lang.Object.wait(Native Method)
java.lang.Thread.parkFor$(Thread.java:2127)
sun.misc.Unsafe.park(Unsafe.java:325)
java.util.concurrent.locks.LockSupport.park(LockSupport.java:161)
java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2035)
java.util.concurrent.PriorityBlockingQueue.take(PriorityBlockingQueue.java:519)
java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1058)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1118)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
java.lang.Thread.run(Thread.java:761)
com.bumptech.glide.load.engine.executor.FifoPriorityThreadPoolExecutor$DefaultThreadFactory$1.run(FifoPriorityThreadPoolExecutor.java:118)
Thread[fifo-pool-thread-2,5,main]
java.lang.Object.wait(Native Method)
java.lang.Thread.parkFor$(Thread.java:2127)
sun.misc.Unsafe.park(Unsafe.java:325)
java.util.concurrent.locks.LockSupport.park(LockSupport.java:161)
java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2035)
java.util.concurrent.PriorityBlockingQueue.take(PriorityBlockingQueue.java:519)
java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1058)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1118)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
java.lang.Thread.run(Thread.java:761)
com.bumptech.glide.load.engine.executor.FifoPriorityThreadPoolExecutor$DefaultThreadFactory$1.run(FifoPriorityThreadPoolExecutor.java:118)
Thread[MonitoringInstrumentation,5,main]
java.lang.Object.wait(Native Method)
android.app.Instrumentation.startActivitySync(Instrumentation.java:420)
android.support.test.runner.MonitoringInstrumentation.access$101(MonitoringInstrumentation.java:96)
android.support.test.runner.MonitoringInstrumentation$4.call(MonitoringInstrumentation.java:410)
android.support.test.runner.MonitoringInstrumentation$4.call(MonitoringInstrumentation.java:407)
java.util.concurrent.FutureTask.run(FutureTask.java:237)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
java.lang.Thread.run(Thread.java:761)
Thread[Instr: android.support.test.runner.AndroidJUnitRunner,5,main]
dalvik.system.VMStack.getThreadStackTrace(Native Method)
java.lang.Thread.getStackTrace(Thread.java:1566)
java.lang.Thread.getAllStackTraces(Thread.java:1616)
android.support.test.runner.MonitoringInstrumentation.getThreadState(MonitoringInstrumentation.java:593)
android.support.test.runner.MonitoringInstrumentation.dumpThreadStateToOutputs(MonitoringInstrumentation.java:588)
android.support.test.runner.MonitoringInstrumentation.startActivitySync(MonitoringInstrumentation.java:417)
android.support.test.rule.ActivityTestRule.launchActivity(ActivityTestRule.java:332)
android.support.test.rule.ActivityTestRule$ActivityStatement.evaluate(ActivityTestRule.java:431)
android.support.test.rule.ActivityTestRule$ActivityStatement.evaluate(ActivityTestRule.java:433)
org.junit.rules.RunRules.evaluate(RunRules.java:20)
org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
org.junit.runners.BlockJ
D/LifecycleMonitor: Lifecycle status change: com.esoxjem.movieguide.listing.MoviesListingActivity@e1d22 in: PAUSED
I/TestRunner: failed: onCreateTest(com.esoxjem.movieguide.listing.MoviesListingActivityAndroidTest)
I/TestRunner: ----- begin exception -----
I/TestRunner: java.lang.RuntimeException: Could not launch intent Intent { act=android.intent.action.MAIN flg=0x10000000 cmp=com.esoxjem.movieguide/.listing.MoviesListingActivity } 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 1520566574627 and now the last time the queue went idle was: 1520566577444. If these numbers are the same your activity might be hogging the event queue.
java.lang.RuntimeException: Could not launch intent Intent { act=android.intent.action.MAIN flg=0x10000000 cmp=com.esoxjem.movieguide/.listing.MoviesListingActivity } 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 1520566574627 and now the last time the queue went idle was: 1520566577444. If these numbers are the same your activity might be hogging the event queue.
at android.support.test.runner.MonitoringInstrumentation.startActivitySync(MonitoringInstrumentation.java:419)
at android.support.test.rule.ActivityTestRule.launchActivity(ActivityTestRule.java:332)
at android.support.test.rule.ActivityTestRule$ActivityStatement.evaluate(ActivityTestRule.java:431)
at android.support.test.rule.ActivityTestRule$ActivityStatement.evaluate(ActivityTestRule.java:433)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:58)
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:375)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1932)
at android.support.test.runner.MonitoringInstrumentation.startActivitySync(MonitoringInstrumentation.java:419)
at android.support.test.rule.ActivityTestRule.launchActivity(ActivityTestRule.java:332)
at android.support.test.rule.ActivityTestRule$ActivityStatement.evaluate(ActivityTestRule.java:431)
at android.support.test.rule.ActivityTestRule$ActivityStatement.evaluate(ActivityTestRule.java:433)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:58)
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:375)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1932)
I/TestRunner: ----- end exception -----
I/TestRunner: finished: onCreateTest(com.esoxjem.movieguide.listing.MoviesListingActivityAndroidTest)
I/MonitoringInstr: Activities that are still in CREATED to STOPPED: 1
I/MonitoringInstr: Unstopped activity count: 1
I/MonitoringInstr: Unstopped activity count: 1
I/MonitoringInstr: Unstopped activity count: 1
D/EGL_emulation: eglMakeCurrent: 0xa2f98ce0: ver 2 0 (tinfo 0xa4cbcb20)
I/MonitoringInstr: Unstopped activity count: 1
I/MonitoringInstr: Unstopped activity count: 1
I/MonitoringInstr: Unstopped activity count: 1
I/MonitoringInstr: Unstopped activity count: 1
I/MonitoringInstr: Unstopped activity count: 1
D/LifecycleMonitor: Lifecycle status change: com.esoxjem.movieguide.listing.MoviesListingActivity@e1d22 in: STOPPED
D/LifecycleMonitor: Lifecycle status change: com.esoxjem.movieguide.listing.MoviesListingActivity@e1d22 in: DESTROYED
I/TestRunner: run finished: 1 tests, 1 failed, 0 ignored
I/MonitoringInstr: waitForActivitiesToComplete() took: 0ms
I/MonitoringInstr: Activities that are still in CREATED to STOPPED: 0
Disconnected from the target VM, address: 'localhost:8638', transport: 'socket'
Tests ran to completion.