gpt4 book ai didi

安卓 Espresso : "No test were found" , "Process crashed"

转载 作者:太空宇宙 更新时间:2023-11-03 10:41:13 25 4
gpt4 key购买 nike

当使用 Espresso 测试我的 Android 应用程序时,我注意到运行配置有 All in Module 的 AndroidTest 找不到测试,而运行 All in Package 成功。

我创建了以下可重现的案例:

  • 使用向导使用 minSdk 8 和空 Activity 创建新的干净应用
  • 使用 espresso 依赖项等配置 gradle(见下文)
  • 使用选项 All in Module 和一个带有 All in Package 的选项创建 AndroidTest Run Configuration
  • 添加带有测试的类(见下文)
  • 使用 All in Package 运行:测试通过
  • 使用 All in Module 运行:未找到测试

使用 All in Module 运行直到几天前都运行良好。我记得所做的更改是将 Android Studio 升级到 1.4,将 Android Support Library 升级到 23.1.0,将 Android Support Repository 升级到 24.0.0。

顺便说一句。 gradlew connectedCheckgradlew createDebugAndroidTestCoverageReport 现在也失败了。

有没有人有解决这个问题的建议?

应用的build.gradle:

apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.1"

defaultConfig {
applicationId "com.example.xyz.apptest"
minSdkVersion 8
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
testCoverageEnabled true
}
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.0'

androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.1') {
// Necessary if your app targets Marshmallow (since Espresso
// hasn't moved to Marshmallow yet)
exclude group: 'com.android.support', module: 'support-annotations'
}
androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2.1') {
// Necessary if your app targets Marshmallow (since Espresso
// hasn't moved to Marshmallow yet)
exclude group: 'com.android.support', module: 'support-annotations'
exclude group: 'com.android.support', module: 'appcompat'
exclude group: 'com.android.support', module: 'support-v4'
exclude module: 'recyclerview-v7'
}
androidTestCompile('com.android.support.test.espresso:espresso-idling-resource:2.2.1') {
// Necessary if your app targets Marshmallow (since Espresso
// hasn't moved to Marshmallow yet)
exclude group: 'com.android.support', module: 'support-annotations'
}
androidTestCompile('com.android.support.test:runner:0.4.1') {
// Necessary if your app targets Marshmallow (since the test runner
// hasn't moved to Marshmallow yet)
exclude group: 'com.android.support', module: 'support-annotations'
}
androidTestCompile('com.android.support.test:rules:0.4.1') {
// Necessary if your app targets Marshmallow (since the test runner
// hasn't moved to Marshmallow yet)
exclude group: 'com.android.support', module: 'support-annotations'

}
}

测试.java

@RunWith(AndroidJUnit4.class)
public class Test1 {

@Rule
public ActivityTestRule<MainActivity> activityTestRule =
new ActivityTestRule<>(MainActivity.class, true, false);

@Before
public void setUp() {
activityTestRule.launchActivity(new Intent());
}

@After
public void cleanUp() {
}

@Test
public void test() {
}
}

在运行窗口中跟踪:

Testing started at 12:14 ...
Waiting for device.
Target device: 3_2_API_10 [emulator-5554]
Uploading file
local path: C:\Users\xyz\Documents\Development\AndroidStudio\AppTest\app\build\outputs\apk\app-debug.apk
remote path: /data/local/tmp/com.example.xyz.apptest
No apk changes detected.
Skipping file upload, force stopping package instead.
DEVICE SHELL COMMAND: am force-stop com.example.xyz.apptest
Uploading file
local path: C:\Users\xyz\Documents\Development\AndroidStudio\AppTest\app\build\outputs\apk\app-debug-androidTest-unaligned.apk
remote path: /data/local/tmp/com.example.xyz.apptest.test
No apk changes detected.
Skipping file upload, force stopping package instead.
DEVICE SHELL COMMAND: am force-stop com.example.xyz.apptest.test
Running tests
Test running startedTest running failed: Instrumentation run failed due to 'Process crashed.'
Empty test suite.

logcat:未发现易感差异。

最佳答案

从基于 API 10 的模拟器切换到 API 17 解决了这个问题。

尽管 API 10 在上周之前运行良好,但它已经变得不可预测了。有时它会运行,但大多数情况下不会。删除单个测试方法可能会使其工作,而将其放回原位可能会使其继续工作(或不工作)。尝试第五次运行测试可能会使其再次运行...

2016 年 3 月 16 日更新:增加 API 10 模拟器的资源使测试再次可用于 API 10...

关于安卓 Espresso : "No test were found" , "Process crashed",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33197121/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com