Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android tests often stall at 'instantiating tests'

When I click the run test button, Android Studio builds and attempts to run the test.

70% of the time, it says "Instantiating tests..." and never goes anywhere from there. If I kill the adb-server, unplug adevice, or kill an emulator, the test suite magically runs fine.

I even saw a bizarre behavior the other night. I unplugged the device while it said Instantiating Tests. Android Studio picked up that it disappeared. I pulled my phone out of my pocket a few hours later, unlocked it, and out of nowhere, it started running the test suite.

Any idea what can cause this behavior? The closest I've found is Android Test stopping in instantiating tests, but that is referring to a different issue.

like image 937
user3534080 Avatar asked Feb 19 '16 02:02

user3534080


People also ask

What is Android test runner?

The test runner handles loading your test package and the app under test to a device, running your tests, and reporting test results. This test runner supports several common testing tasks, including the following: Writing JUnit tests. Accessing the app's context. Filtering tests.

When should you use the Android test directory?

A typical project in Android Studio contains two directories in which you place tests. The androidTest directory should contain the tests that run on real or virtual devices. Such tests include integration tests, end-to-end tests, and other tests where the JVM alone cannot validate your app's functionality.

What is runtime test in Android?

The suite is built using the Android testing framework. The runner is implemented as a single instrumentation test that executes the test package and parses the result log. The logs are taken directly from the device (logcat).

What is the purpose of unit tests in Android?

Unit tests or small tests only verify a very small portion of the app, such as a method or class. End-to-end tests or big tests verify larger parts of the app at the same time, such as a whole screen or user flow.


2 Answers

I had the same, issue would only occur when running as debug though. Never had it when running normally.

I fixed it by removing Test Orchestrator in my Build.gradle.

//Disable Me //        testInstrumentationRunnerArguments clearPackageData: 'true' //        testOptions { //            execution 'ANDROID_TEST_ORCHESTRATOR' //        } 
like image 109
user1228891 Avatar answered Sep 27 '22 20:09

user1228891


This happened to me on my OnePlus 5 as well - I couldn't make it running. Seems like it's related to this device only.

I end up using an emulator and other phones, which works fine.

like image 21
Micer Avatar answered Sep 27 '22 18:09

Micer