Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to continue an Android instrumentation test run after exception?

Apparently an instrumentation test run is stopped when on exception occurs in the instrumented application:

Test failed to run to completion. Reason: 'Instrumentation run failed due to 'Exception''. Check device logcat for details

Is this the desired behavior or a misconfiguration in a custom instrumentation runner?

I'm using a custom MonitorinInstrumentation [1] in order to automate acceptance tests.

Unfortunately test execution is canceled when on exception occurs in one test. I want the test suite to complete and only mark the failed tests, like in JUnit.

Is there a general approach to execute (connected) tests without quitting the whole instrumentation in case an exception occurs in one test?

  1. https://github.com/cucumber/cucumber-jvm/blob/master/examples/android/android-studio/Cukeulator/app/src/androidTest/java/cucumber/cukeulator/test/Instrumentation.java
like image 770
André Diermann Avatar asked Apr 26 '16 09:04

André Diermann


People also ask

How run all test cases in Android?

Run all tests in a single class The default keyboard shortcut for this is Ctrl+Shift+F10 on Linux.

What is Android instrumentation testing?

Instrumented tests run on Android devices, whether physical or emulated. As such, they can take advantage of the Android framework APIs. Instrumented tests therefore provide more fidelity than local tests, though they run much more slowly.

What is instrumentation in mobile testing?

Instrumentation is a process to prepare the application for testing or automation. Part of the instrumentation process may add "instruments" that allow the testing framework to gain access to parts of the application. Perfecto provides tools for instrumenting mobile applications for different purposes.


1 Answers

Instrumentation tests raise an Exception when something goes wrong (e.g. some conditions that you want to check). You can usually avoid some test to fail using try catch statement(or changing those checks). In this case there's something that made Dalvik Virtual Machine stop. This is usually caused by a crash in your app. Try to check carefully your tests flow to analyze if there are some crashes. Also, be sure to not use System.exit(0) in onDestroy() in some of your activities because this can cause your problem. I hope to can help you.

like image 115
Lorenzo Camaione Avatar answered Oct 11 '22 17:10

Lorenzo Camaione