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
activitytestrule
the @rule must be public
testorchestrator
@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 {
            main.java.srcDirs += 'src/main/kotlin'
            androidTest.java.srcDirs += '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


@RunWith(AndroidJUnit4::class)
@SmallTest
class TradersActivityTest {

    private lateinit var stringToBetyped: String

    @get:Rule
    var activityRule: ActivityTestRule<TradersActivity> = ActivityTestRule(TradersActivity::class.java)

    @Before
    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(AndroidJUnit4.java:92)
at androidx.test.ext.junit.runners.AndroidJUnit4.loadRunner(AndroidJUnit4.java:82)
at androidx.test.ext.junit.runners.AndroidJUnit4.loadRunner(AndroidJUnit4.java:51)
at androidx.test.ext.junit.runners.AndroidJUnit4.<init>(AndroidJUnit4.java:46)
at java.lang.reflect.Constructor.newInstance(Native Method)
at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
at androidx.test.internal.runner.junit4.AndroidAnnotatedBuilder.runnerForClass(AndroidAnnotatedBuilder.java:63)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
at androidx.test.internal.runner.AndroidRunnerBuilder.runnerForClass(AndroidRunnerBuilder.java:153)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at androidx.test.internal.runner.TestLoader.doCreateRunner(TestLoader.java:73)
at androidx.test.internal.runner.TestLoader.getRunnersFor(TestLoader.java:104)
at androidx.test.internal.runner.TestRequestBuilder.build(TestRequestBuilder.java:789)
at androidx.test.runner.AndroidJUnitRunner.buildRequest(AndroidJUnitRunner.java:544)
at androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:387)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1879)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Native Method)
at androidx.test.ext.junit.runners.AndroidJUnit4.loadRunner(AndroidJUnit4.java:72)
... 16 more
Caused by: org.junit.runners.model.InitializationError
at org.junit.runners.ParentRunner.validate(ParentRunner.java:418)
at org.junit.runners.ParentRunner.<init>(ParentRunner.java:84)
at org.junit.runners.BlockJUnit4ClassRunner.<init>(BlockJUnit4ClassRunner.java:65)
at androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner.<init>(AndroidJUnit4ClassRunner.java:43)
at androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner.<init>(AndroidJUnit4ClassRunner.java:48)
... 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

@Test
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

@RunWith(AndroidJUnit4::class)

@LargeTest

class MainActivityTest {

    private val TAG = "MainActivityTest"

    @get:Rule
    val activityRule = ActivityTestRule(MainActivity::class.java)
}

follow the link below:- https://developer.android.com/training/testing/junit-rules

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'

not

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.

@Test
fun someTestMethod(someParams: Int) { // delete method params
    assert(1==1)
}

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:

@Test
fun willThrowInitializationErrorBecauseReturnsNonUnitValue(): Int {
    return 0
}

@Test
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.