Tôi tiếp tục gặp phải lỗi sau khi cố gắng thực hiện các thử nghiệm của mình trong Android Studio: Chạy thử nghiệm không thành công: Không thể tìm thấy thông tin thiết bị cho: ComponentInfo {.test/android.support.test .runner.AndroidJUnitRunner}Lỗi thử nghiệm của Android Studio Espresso: Bộ thử nghiệm trống
Lớp thử nghiệm của tôi nằm trong thư mục androidTest/java và có một hàm tạo. Build.gradle của tôi cũng chính xác. Bất kỳ trợ giúp được đánh giá cao.
Kiểm tra Lớp
@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'
}
Khi nghi ngờ, hãy tham khảo các ví dụ chính thức: https://github.com/googlesamples/android-testing. –