android studio 仪器测试出错

w22net 2020-04-05 10:31:03
运行仪器测试代码 出现如下错误,什么情况????
@RunWith(AndroidJUnit4.class)
@LargeTest
public class MainActivityInstrumentationTest {

private static final String STRING_TO_BE_TYPED = "Peter";

@Rule
public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule<>(
MainActivity.class);

@Test
public void sayHello(){
onView(withId(R.id.editText)).perform(typeText(STRING_TO_BE_TYPED), closeSoftKeyboard()); //line 1

onView(withText("Say hello!")).perform(click()); //line 2

String expectedText = "Hello, " + STRING_TO_BE_TYPED + "!";
onView(withId(R.id.textView)).check(matches(withText(expectedText))); //line 3
}

}






Waiting for process to come online...
Connected to process 27807 on device 'emulator-5554'.
Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.
I/.testingexampl: The ClassLoaderContext is a special shared library.
I/chatty: uid=10229(com.example.testing.testingexample) identical 2 lines
I/.testingexampl: The ClassLoaderContext is a special shared library.
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.testing.testingexample, PID: 27807
java.lang.RuntimeException: Unable to instantiate instrumentation ComponentInfo{com.example.testing.testingexample.test/android.support.test.runner.AndroidJUnitRunner}: java.lang.ClassNotFoundException: Didn't find class "android.support.test.runner.AndroidJUnitRunner" on path: DexPathList[[zip file "/system/framework/android.test.runner.jar", zip file "/system/framework/android.test.mock.jar", zip file "/data/app/com.example.testing.testingexample.test-QHPNwTZSz7BJlNrcRtX2iQ==/base.apk", zip file "/data/app/com.example.testing.testingexample-Abs7ptaD3j2-bNdvLCWTfg==/base.apk"],nativeLibraryDirectories=[/system/lib, /system/product/lib]]
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6358)
at android.app.ActivityThread.access$1300(ActivityThread.java:220)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1852)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7319)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:934)
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.test.runner.AndroidJUnitRunner" on path: DexPathList[[zip file "/system/framework/android.test.runner.jar", zip file "/system/framework/android.test.mock.jar", zip file "/data/app/com.example.testing.testingexample.test-QHPNwTZSz7BJlNrcRtX2iQ==/base.apk", zip file "/data/app/com.example.testing.testingexample-Abs7ptaD3j2-bNdvLCWTfg==/base.apk"],nativeLibraryDirectories=[/system/lib, /system/product/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6354)
at android.app.ActivityThread.access$1300(ActivityThread.java:220) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1852) 
at android.os.Handler.dispatchMessage(Handler.java:107) 
at android.os.Looper.loop(Looper.java:214) 
at android.app.ActivityThread.main(ActivityThread.java:7319) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:934) 
I/Process: Sending signal. PID: 27807 SIG: 9

Started running tests
Test running failed: Instrumentation run failed due to 'Process crashed.'
...全文
505 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
w22net 2020-04-07
  • 打赏
  • 举报
回复 1
找到原因了,build.gradle 按如下注释修改即可 defaultConfig { applicationId "com.example.testing.testingexample" minSdkVersion 15 targetSdkVersion 29//22 versionCode 1 versionName "1.0" //testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" }

80,354

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧