Reputation: 163
I keep running into the following error when trying to execute my tests in Android Studio: Test running failed: Unable to find instrumentation info for: ComponentInfo{.test/android.support.test.runner.AndroidJUnitRunner}
My test class is in the androidTest/java directory and has a constructor. My build.gradle is correct too. Any help is appreciated.
Test Class
@RunWith(AndroidJUnit4.class)
@LargeTest
public class AndroidUITests extends ActivityInstrumentationTestCase2<UserActivity>{
private UserActivity userActivity;
public AndroidUITests() {
super(UserActivity.class);
}
@Before
public void setUp() throws Exception {
super.setUp();
injectInstrumentation(InstrumentationRegistry.getInstrumentation());
userActivity = getActivity();
}
@Test
public void testPhoneIconIsDisplayed() {
// When the phone_icon view is available,
// check that it is displayed.
onView(ViewMatchers.withId(R.id.groupCreate)).perform(click())
.check(matches(withText("Enter a name")));
}
}
app/build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
}
packagingOptions {
exclude 'LICENSE.txt'
}
}
dependencies {
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.0'
androidTestCompile 'com.android.support.test:testing-support-lib:0.1'
}
Upvotes: 16
Views: 20394
Reputation: 811
My issue was that the field 'testInstrumentationRunner' is specified in the build.gradle (app). Change that to the androidx if you are using it (androidx.test.runner.AndroidJUnitRunner)
Hope it helps someone, cheers!
Upvotes: 0
Reputation: 2060
If anyone still bother with this in 2018, here is working setup:
build.gradle
(required):
<...snip...>
android {
defaultConfig {
<...snip...>
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
// ^^^ here it is (first)!
}
<...snip...>
dependencies {
<...snip...>
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
// ^^^ all three required ^^^ (second)
}
And in instrumented tests (required too):
import androidx.test.espresso.Espresso.onData
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.*
import androidx.test.espresso.assertion.ViewAssertions.*
import androidx.test.espresso.matcher.RootMatchers.*
import androidx.test.espresso.matcher.ViewMatchers.*
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.LargeTest
import org.hamcrest.Matchers.*
import org.junit.Test
import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
@LargeTest
class ApplicationTest {
@Test
fun thruStillThrullyThrue() {
// do interaction with some UI
onView(withId(R.id.myButtonOnMyActivity)).perform(click())
// assert expected result
onView(withId(R.id.myTextViewOnMyActivity)).check(matches(isDisplayed()))
}
}
// (third)
Upvotes: 0
Reputation: 11555
If you get such error message:
Class not found: "com.example.product.package.name.SomeSpecificTest" Empty test suite.
You need to make sure if your Espresso test is added under Android Instrumented Tests
section in Run/Debug Configurations
.
It seems like Android Studio 3.1.3 is sometimes adding it incorrectly to Android JUnit
section instead.
Make sure it looks something like this:
Also, worth mentioning that I've noticed, that this issue occurs for me while a non Debug
build variant is selected.
Upvotes: 7
Reputation: 7711
You have to update the test "Edit Configuration" and include the AndroidJUnitRunner as the instrumentation runner.
I found the solution in this video: https://youtu.be/TGU0B4qRlHY?t=9m36s
Updated
Adding what @loeschg suggest: Make sure you check the logcat logs to ensure something isn't causing issues (crash) before the test is even run. Bad code in the @BeforeClass block could resulted in the "Empty Test Suite" message in Android Studio despite having properly set the test runner.
Upvotes: 25
Reputation: 30581
While the question is already answered, figured it was worth posting for future visitors.
Make sure you check the logcat logs to ensure something isn't causing issues (crash) before the test is even run. I had bad code in my @BeforeClass
block which resulted in the "Empty Test Suite" message in Android Studio despite having properly set the test runner.
Upvotes: 27
Reputation: 10685
I'm fairly certain android.support.test.runner.AndroidJUnitRunner
is provided by the runner library.
it should look like this
dependencies {
...
androidTestCompile 'com.android.support.test:runner:0.2'
}
Upvotes: 0