JUnit4 - AssertionFailedError: No tests found

15,695

Solution 1

I found the problem. It was missed code in build.gradle in the main module. If you have this problem I advise to start with adding this line:

android {
    ...

    defaultConfig {
        ...

        testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
    }
...
}

Solution 2

android {
    defaultConfig {
        testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
    }
}

dependencies {
    androidTestImplementation "androidx.test:runner:1.4.0"
    androidTestImplementation "androidx.test.ext:junit:1.1.3"
}

@RunWith(AndroidJUnit4::class)
class SomeInstrumentedTest {}
Share:
15,695
Val
Author by

Val

Updated on June 03, 2022

Comments

  • Val
    Val about 2 years

    I'm using AndroidJUnitRunner with Espresso.

    I wrote a simple test but always receive this exception. According to Stackoverflow answers, the problem is messing up the JUnit3 and JUnit4 but I have never used JUnit3 in my project.

    junit.framework.AssertionFailedError: No tests found in com.walletsaver.app.test.espresso.SignUpPopupTest

    package com.walletsaver.app.test.espresso;
    
    import android.support.test.rule.ActivityTestRule;
    import android.support.test.runner.AndroidJUnit4;
    import android.test.suitebuilder.annotation.SmallTest;
    
    import com.walletsaver.app.activity.LoginActivity;
    
    import org.junit.Rule;
    import org.junit.Test;
    import org.junit.runner.RunWith;
    
    import static android.support.test.espresso.Espresso.onView;
    import static android.support.test.espresso.action.ViewActions.click;
    import static android.support.test.espresso.matcher.ViewMatchers.withText;
    
    @RunWith(AndroidJUnit4.class)
    @SmallTest
    public class SignUpPopupTest {
    
        @Rule
        public ActivityTestRule<LoginActivity> mActivityRule =
                new ActivityTestRule<>(LoginActivity.class);
    
        @Test
        public void checkSignUpPopup() throws Exception {
            onView(withText("Sign Up")).perform(click());
        }
    }
    

    Run configuration: enter image description here

    Output: enter image description here

  • Omer Malik
    Omer Malik almost 8 years
    Thanks alot it solved the problem, can you tell why we have to add this?
  • Val
    Val almost 8 years
    @OmerMalik I tried to mention android.support.test.runner.AndroidJUnitRunner in Run configuration but this didn't have an effect. Then I wrote it directly in build.gradle and it helped. It seems it should be set in defaultConfig to be visible.
  • Omer Malik
    Omer Malik almost 8 years
    I read the android documentation and it is mentioned their, I missed the step, thank alot
  • Del
    Del almost 8 years
    as a follow-up, one may see the message "Unable to find instrumentation info for". To fix that, tell the Android Studio launch configuration to use the specific test runner from the build.gradle file
  • xyz
    xyz almost 5 years
    For AndroidX, testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
  • huskygrad
    huskygrad almost 4 years
    Hi, I have Dynamic Feature Modules in my app. For tests in the Feature Module, I'm using a custom testInstrumentationRunner , which is located in the app module. I'm getting this error "Test running failed: Instrumentation run failed due to 'Process crashed.'" Any idea how will it work across multiple modules? @Val
  • Chenhe
    Chenhe almost 4 years
    For AndroidX, use testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" instead.