title: Build local unit tests (No instrumentation registered! Must run under a registering instrumentation)
body: <p>Take a look at the official <a href="https://developer.android.com/training/testing/unit-testing/local-unit-tests#include-framework-dependencies" rel="noreferrer">documentation</a>. The section <strong><em>Include framework dependencies</em></strong> gives an example of how to set up a local unit testing to work with the environment android sdk. But if you do everything as in the example, the test does not start. I get an error instead </p>
  
  <blockquote>
    <p>java.lang.IllegalStateException: No instrumentation registered! Must
    run under a registering instrumentation.</p>
  </blockquote>
  
  <p>All attempts were made on a new project. Android Studio 3.3, gradle-4.10.1, build:gradle:3.3.0, Kotlin, and include Androidx artifacts.</p>
  
  <p>Then added the following lines to the project with the specified configuration:</p>
  
  <p><strong>build.gradle</strong></p>
  
  <pre><code>android {
      // ...
      testOptions {
          unitTests.includeAndroidResources = true
      }
  }
  
  dependencies {
      // ...
      // Already exist
      testImplementation 'junit:junit:4.12'
      // Added this line
      testImplementation 'androidx.test:core:1.0.0'
  }
  </code></pre>
  
  <p><strong>And the test body itself:</strong></p>
  
  <pre><code>package com.example.myapplication
  
  import android.content.Context
  import androidx.test.core.app.ApplicationProvider
  import org.junit.Test
  
  class ExampleUnitTest {
  
      val context = ApplicationProvider.getApplicationContext&lt;Context&gt;()
  
      @Test
      fun readStringFromContext_LocalizedString() {
          System.out.println(context.applicationInfo.packageName)
      }
  }
  </code></pre>
  
  <p>What am I doing wrong?</p>
  
  <hr>
  
  <pre><code>apply plugin: 'com.android.application'
  
  apply plugin: 'kotlin-android'
  
  apply plugin: 'kotlin-android-extensions'
  
  android {
      compileSdkVersion 28
      defaultConfig {
          applicationId "com.example.myapplication"
          minSdkVersion 15
          targetSdkVersion 28
          versionCode 1
          versionName "1.0"
          testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
      }
      buildTypes {
          release {
              minifyEnabled false
              proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
          }
      }
      testOptions {
          unitTests.includeAndroidResources = true
      }
  }
  
  dependencies {
      implementation fileTree(dir: 'libs', include: ['*.jar'])
      implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
      implementation 'androidx.appcompat:appcompat:1.0.0-beta01'
      implementation 'androidx.core:core-ktx:1.1.0-alpha03'
      implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
      testImplementation 'junit:junit:4.12'
      testImplementation 'androidx.test:core:1.0.0'
      androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
      androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'
  }
  </code></pre>