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 {}
![Val](https://i.stack.imgur.com/wOcGR.jpg?s=256&g=1)
Author by
Val
Updated on June 03, 2022Comments
-
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()); } }
-
Omer Malik almost 8 yearsThanks alot it solved the problem, can you tell why we have to add this?
-
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 inbuild.gradle
and it helped. It seems it should be set indefaultConfig
to be visible. -
Omer Malik almost 8 yearsI read the android documentation and it is mentioned their, I missed the step, thank alot
-
Del almost 8 yearsas 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 almost 5 yearsFor AndroidX, testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
-
huskygrad almost 4 yearsHi, 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 almost 4 yearsFor AndroidX, use
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
instead.