1、添加gralde依赖
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
2、androidTest目录添加单元测试代码
UiDevice就是uiautomator中的工具类
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
UiDevice uiDevice = UiDevice.getInstance(getInstrumentation());
uiDevice.findObject(By.res(“com.android.launcher3:id/bubble_text”)).click();
}
}