Delegate runner 'androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner' for AndroidJUnit4 could not be loaded

Delegate runner 'androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner' for AndroidJUnit4 could not be loaded

delegate runner could not be loaded
delegate runner 'org robolectric robolectrictestrunner for androidjunit4 could not be loaded
the @rule must be public
@runwith androidx
android runner
applicationprovider getapplicationcontext

I try to run Kotlin instrumentation tests for android.

In my app/build.gradle:

    android {
        dataBinding {
            enabled = true
        compileSdkVersion 28
        defaultConfig {
            applicationId "com.myproject"
            minSdkVersion 18
            targetSdkVersion 28
            versionCode 6
            versionName "0.0.7"
            testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

        sourceSets {
   += 'src/main/kotlin'
   += 'src/androidTest/kotlin'

androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0-alpha02'
    androidTestImplementation 'androidx.test.ext:junit:1.1.0'
    androidTestImplementation 'androidx.test:rules:1.1.2-alpha02'
    androidTestImplementation 'androidx.test:runner:1.1.2-alpha02'

In folder /app/src/androidTest/kotlin/com/myproject/ I has Kotlin test:

import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import org.junit.Rule
import org.junit.runner.RunWith

import androidx.test.rule.ActivityTestRule
import com.myproject.ui.activity.TradersActivity
import org.junit.Before

class TradersActivityTest {

    private lateinit var stringToBetyped: String

    var activityRule: ActivityTestRule<TradersActivity> = ActivityTestRule(

    fun initValidString() {
        // Specify a valid string.
        stringToBetyped = "Espresso"


but when I run test I get error:

$ adb shell am instrument -w -r   -e debug false -e class 'com.myproject.TradersActivityTest' com.myproject.debug.test/androidx.test.runner.AndroidJUnitRunner
Client not ready yet..
Started running tests

java.lang.RuntimeException: Delegate runner 'androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner' for AndroidJUnit4 could not be loaded.
at androidx.test.ext.junit.runners.AndroidJUnit4.throwInitializationError(
at androidx.test.ext.junit.runners.AndroidJUnit4.loadRunner(
at androidx.test.ext.junit.runners.AndroidJUnit4.loadRunner(
at androidx.test.ext.junit.runners.AndroidJUnit4.<init>(
at java.lang.reflect.Constructor.newInstance(Native Method)
at androidx.test.internal.runner.junit4.AndroidAnnotatedBuilder.runnerForClass(
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(
at androidx.test.internal.runner.AndroidRunnerBuilder.runnerForClass(
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(
at androidx.test.internal.runner.TestLoader.doCreateRunner(
at androidx.test.internal.runner.TestLoader.getRunnersFor(
at androidx.test.runner.AndroidJUnitRunner.buildRequest(
at androidx.test.runner.AndroidJUnitRunner.onStart(
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Native Method)
at androidx.test.ext.junit.runners.AndroidJUnit4.loadRunner(
... 16 more
Caused by: org.junit.runners.model.InitializationError
at org.junit.runners.ParentRunner.validate(
at org.junit.runners.ParentRunner.<init>(
at org.junit.runners.BlockJUnit4ClassRunner.<init>(
at androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner.<init>(
at androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner.<init>(
... 18 more

Tests ran to completion.

The error message displayed when I delete the @Test method.

You can try to put a @Test method and run

public void signInTest() {


Migrating Junit4 tests to androidx: What causes 'delegate runner , Removing @RunWith(AndroidJUnit4.class) annotations from the test classes fixed the issue, although I can't really say why or how it fixed it. With many wins on Super Tuesday, former VP Joe Biden has become the front runner in the delegate count. Vermont Senator Bernie Sanders isn’t far behind, with less than 100 fewer delegates as of

I faced this problem in kotlin , used below code and it worked



class MainActivityTest {

    private val TAG = "MainActivityTest"

    val activityRule = ActivityTestRule(

follow the link below:-

2020 Democratic Delegate Tracker : NPR, A candidate needs 1991 delegates to become the Democratic Party's presidential nominee. Even after effectively securing the nomination in� Joe Biden secured the pledged delegates needed to become the Democratic presidential nominee on June 5.

I just wasted all day on this issue 😵

I'm guessing you are using the multiplatform plugin like I am.

I was about to give up on trying to moving my instrumented tests to src/androidTest/kotlin instead of src/androidTest/java

when I decided to log kotlin.sourcesets.names, which printed

[androidAndroidTest, androidAndroidTestDebug, androidDebug, androidMain, androidRelease, androidTest, androidTestDebug, androidTestRelease, commonMain, commonTest, iosArm32Main, iosArm32Test, iosArm64Main, iosArm64Test, iosX64Main, iosX64Test, macosX64Main, macosX64Test]

Soo I realized in order for dependencies to resolve correctly I needed to change

androidTestImplementation -> androidAndroidTestImplementation
testImplementation -> androidTestImplementation

They don't describe this in the documentation of course. (as far as I have found)

... so for example, for you, I think the dependencies for your instrumented test dependencies should be:

androidAndroidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0-alpha02'


androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0-alpha02'

Delegate runner 'org.robolectric.RobolectricTestRunner' for , Delegate runner 'org.robolectric.RobolectricTestRunner' for AndroidJUnit4 could not be loaded. #374. Closed. ampeixoto opened this issue on� Former Vice President Joe Biden has been the last active Democratic candidate running to face off against President Trump in November since April, but at that point he was still far short of the

I got this error when I have some parameters in my test method. So, if you have it - delete it.

fun someTestMethod(someParams: Int) { // delete method params

Delegate runner 'androidx.test.internal.runner.junit4 , This java test fails with the Delegate runner for AndroidJunit4 could not be loaded error. But If I remove the #RunWith annotation, it works. Also, if I replace the� Delegate runner 'androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner' for AndroidJUnit4 could not be loaded Ask Question Asked 1 year, 2 months ago

You don't have any functions annotated with @Test. This is likely the cause of the issue. I've run my own test using the AndroidJUnit4 runner on a class without @Test functions, and reconstructed this behavior.

The AndroidJUnit4 JUnit4 runner is the cause of this issue, and despite its attempt to provide a detailed message (see the code where the exception is thrown), it gives you a wrong message.

The following are more ways to achieve this error:

fun willThrowInitializationErrorBecauseReturnsNonUnitValue(): Int {
    return 0

fun willThrowInitializationErrorBecauseTakesParameters(param: Int) {

The error is generated by the fact that you're writing JUnit4 style tests, and they're expected to conform to JUnit4 semantics, but it would be nice if the error message were more clear.

To make matters worse, if one test function is messed up the runner won't run any tests because the InitializationError is thrown in the constructor of the AndroidJUnit4 class.

Attempted to use AndroidJUnit4 with standard JUnit runner and , Delegate runner 'androidx.test.internal.runner.junit4. AndroidJUnit4ClassRunner' for AndroidJUnit4 could not be loaded. 6 个月ago� A simple majority (1,990) of the total delegate votes (3,979) is required to become the nominee. The campaign for the 2020 Democratic presidential nomination began on July 28, 2017, when Maryland Congressman John Delaney became the first candidate to announce his run for president.

Who Will Win The 2020 Democratic Primary?, Attempted to use AndroidJUnit4 with standard JUnit runner and delegate runner ' org.robolectric.RobolectricTestRunner'could not be loaded. no instrumentation� 0 delegates. Uninstructed. 0 delegates. Joe Walsh. 0 delegates. Today's Races. There are no races today. Check out the Events Calendar for upcoming Primaries and Caucuses. Recent Races. Candidates

Inside the Super Tuesday delegate math, java.lang.Exception: Delegate runner 'androidx.test.internal.runner.junit4. AndroidJUnit4ClassRunner' for AndroidJUnit4 could not be loaded. Check your build� Using South Carolina as a springboard, Joe Biden has won resounding victories across three weeks of primary contests that have put him on track to win the 2020 Democratic presidential nomination.

We're also charting how many delegates, on average, each candidate is projected to have pledged to them at each point in the primary season, along with a� ABC News is your ultimate source for the 2020 Presidential Election. Get the latest in election news, live updates, debates, candidates, issues, polls, analysis, and results.