简体   繁体   中英

Test failed to run to completion. Reason: 'Instrumentation run failed due to 'Process crashed. when using Espresso

I have around 200 tests running using Espresso. Most of them are large tests. While tests are running app gets crashed and in logs it says,

Test failed to run to completion. Reason: 'Instrumentation run failed due to 'Process crashed.>

I assume its due to OutOfMemory issue. Is there any fix available to clear memory in teardown method, so that we can clear memory after each test finishes? Or is there any other work around to fix this issue? I have tried using android:largeHeap="true" in test manifest file. But its not working. Here is the complete log,

java.lang.OutOfMemoryError: Failed to allocate a 50452 byte allocation with 43158 free bytes and 42KB until OOM
at java.lang.AbstractStringBuilder.enlargeBuffer(AbstractStringBuilder.java:95)
at java.lang.AbstractStringBuilder.append0(AbstractStringBuilder.java:163)
at java.lang.StringBuilder.append(StringBuilder.java:288)
at java.lang.StringBuilder.append(StringBuilder.java:44)
at android.support.test.espresso.core.deps.guava.base.Joiner.appendTo(Joiner.java:111)
at android.support.test.espresso.core.deps.guava.base.Joiner.appendTo(Joiner.java:152)
at android.support.test.espresso.core.deps.guava.base.Joiner.appendTo(Joiner.java:140)
at android.support.test.espresso.util.HumanReadables.getViewHierarchyErrorMessage(HumanReadables.java:76)
at android.support.test.espresso.NoMatchingViewException.getErrorMessage(NoMatchingViewException.java:87)
at android.support.test.espresso.NoMatchingViewException.<init>(NoMatchingViewException.java:59)
at android.support.test.espresso.NoMatchingViewException.<init>(NoMatchingViewException.java:46)
at android.support.test.espresso.NoMatchingViewException$Builder.build(NoMatchingViewException.java:145)
at android.support.test.espresso.base.ViewFinderImpl.getView(ViewFinderImpl.java:95)
at android.support.test.espresso.ViewInteraction$1.run(ViewInteraction.java:120)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5832)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)

I can be wrong but as I can see you first have NoMatchingViewException , this means that something is wrong in your test and expected view is not found, then when Espresso tried to create error message you've received OOM error. So seems the root cause is NoMatchingViewException . So maybe you should fix it first.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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