Android Studio 1.5使用junit单元测试,以及“Test running startedTest running failed: Instrumentation run failed
来源:互联网 发布:强矩阵和弱矩阵 编辑:程序博客网 时间:2024/04/27 15:16
Android Studio 1.5创建的工程,会生成两个默认的测试目录: test,androidTest,其中, test目录为在本机执行单元测试代码的目录, androidTest为在Android设备上执行单元测试代码的目录。
目录如下图所示:
对于新建的工程,默认会生成相应的测试代码例子。如下图所示:
请注意上图的两个文件图标的差别,一个文件的图标的右上角是两个三角标记,另一个文件的右下角是个时钟的标记。
右击 androidTest目录下的 ApplicationTest.java,就会出现执行测试用例的菜单。如下图:
但是当右击 test目录下的 ExampleUnitTest.java则没有任何的运行菜单。如下图:
那么,如何执行 test目录下的 ExampleUnitTest.java呢?
操作方法为 "View"-> "Tool Windows"-> "Build Variants",然后,切换 TestArtifact从 Android Instrumentation Tests到 Unit Tests。
如下图:
切换 Test Artifact
可以看到,切换完成后,两个文件的图标互换了一下:
此时右击 test目录下的 ExampleUnitTest.java则会出现 Run 'ExampleUnitTest', Debug'ExampleUnitTest'的菜单了。
如下图:
至于
这个问题,是由于Android Studio 的BUG,导致的,一般是没有执行上述的切换命令,然后右击 test目录下的 ExampleUnitTest.java依旧会出现 Run'ExampleUnitTest', Debug 'ExampleUnitTest'的菜单,然后点击后,会让我们选择运行的设备,这个时候,明显是把我们当作可以在设备上运行的测试用例了,因此,找不到是必然的。
应对这个BUG的解决方法,就是清理代码,然后重新加载工程,一般可以解决这个问题了。
- Android Studio 1.5使用junit单元测试,以及“Test running startedTest running failed: Instrumentation run failed
- 解决Test running failed: Instrumentation run failed due to 'java.lang.IncompatibleClassChangeError'
- 【转载常见问题】Test Running Failed单元测试
- Test running failed: Unable to find instrumentation info for: ComponentInfo
- android单元测试Test run failed: Unable to find instrumentation target package: com.abc.wallpaper.test
- Android单元测试Test run failed: Unable to find instrumentation target package
- Android单元测试异常总结---Test run failed:Unable to find instrumentation target package
- Test running failed: Unable to find instrumentation info for: ComponentInfo{xxxxxxx}
- Test run failed: Instrumentation run failed due to 'Process crashed.'
- Android问题:Test run failed: Instrumentation run failed due to 'java.lang.RuntimeException'
- 安卓单元测试错误Test run failed: Unable to find instrumentation target package解决办法
- 【转】Andriod 单元测试 Test run failed:Unable to find instrumentation target package的问题
- android 单元测试Test run failed: Test run failed to complete. Expected 1 tests, received 0
- android 单元测试Test run failed: Test run failed to complete. Expected 1 tests, received 0
- Android异常总结---Test run failed:Unable to find instrumentation target package
- Test run failed: Unable to find instrumentation target package: android.support.v7.appcompat
- Test run failed:Unable to find instrumentation target package
- Test run failed: Instrumentation run failed due to 'java.lang.ClassNotFoundException'
- 加入我们一起来测试 PostgreSQL 9.6
- web安全
- 数据库设计之数据库tinyint字段与Int字段的使用
- 聊聊并发(5):原子操作的实现原理
- DOM对象和JQuery对象的区别
- Android Studio 1.5使用junit单元测试,以及“Test running startedTest running failed: Instrumentation run failed
- android studio使用git管理+github远程协作
- 屏幕旋转相关的参数
- 聊聊并发(6)ConcurrentLinkedQueue的实现原理分析
- iOS-最新App Store应用提审攻略
- 哥伦布编码和解码
- 服务器1521端口被关闭,如何开启
- MongoDB
- Ubuntu:虚拟机三种网络模式该如何上网指导