Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Test Orchestrator not working with Android X

I have recently migrated my project to use AndroidX, and have configured test orchestrator for my espresso tests on gradle using the following docs:

https://developer.android.com/training/testing/junit-runner#using-android-test-orchestrator

I have the dependency:

androidTestUtil 'androidx.test:orchestrator:1.1.0-beta01'

However, none of my tests are executed and looks like they fail when running gradle runs the following adb shell command i.e:

adb shell 'CLASSPATH=$(pm path android.support.test.services) app_process / \
  android.support.test.services.shellexecutor.ShellMain am instrument -w -e \
  targetInstrumentation com.example.test/androidx.test.runner.AndroidJUnitRunner \
  android.support.test.orchestrator/.AndroidTestOrchestrator'

from looking at the above: It seems like it is trying to execute this command with android support version as opposed to the androidx version.

It doesn't seem to be documented anywhere what to use for androidx.

like image 930
FlashAsh80 Avatar asked Oct 11 '18 11:10

FlashAsh80


People also ask

Why do you use AndroidJUnitRunner when running UI tests?

When you use AndroidJUnitRunner to run your tests, you can access the context for the app under test by calling the static ApplicationProvider. getApplicationContext() method. If you've created a custom subclass of Application in your app, this method returns your custom subclass's context.

What is AndroidJUnit4?

AndroidJUnit4 is the class test runner. This is the thing that will drive the tests for a single class. You annotate your test classes with this: @RunWith(AndroidJUnit4. class) public class MyActivityTest { ... }

What is test orchestrator?

Android Test Orchestrator is a tool which allows you to run each of your app's tests within its own invocation of Instrumentation. This means that each test (method annotated with @Test ) will be run on a separate instance of AndroidJUnitRunner.

What is Android unit testing?

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. Medium tests are in between and check the integration between two or more units.


Video Answer


2 Answers

Purely by guessing, I changed the following in my gradle config

from:

  testOptions {
    execution 'ANDROID_TEST_ORCHESTRATOR'
  }

to

  testOptions {
    execution 'ANDROIDX_TEST_ORCHESTRATOR'
  }

and all seems to work.

like image 144
FlashAsh80 Avatar answered Oct 22 '22 20:10

FlashAsh80


For anyone else struggling with the Cannot convert string value 'ANDROIDX_TEST_ORCHESTRATOR' to an enum value of type 'com.android.builder.model.TestOptions$Execution' (valid case insensitive values: HOST, ANDROID_TEST_ORCHESTRATOR) error message, ANDROIDX_TEST_ORCHESTRATOR seems to be incompatible with the latest version of IntelliJ (2018.3.5), it worked fine in Android Studio (3.3.2).

like image 22
realitydisorder Avatar answered Oct 22 '22 20:10

realitydisorder