[英]Android Espresso: “No test were found” , “Process crashed”
When testing my Android app with Espresso, I noticed that running an AndroidTest configured with All in Module
finds no tests, while running All in Package
succeeds. 在使用Espresso测试我的Android应用程序时,我注意到运行配置了
All in Module
的AndroidTest找不到测试,而运行All in Package
成功。
I created the following reproducible case: 我创建了以下可重现的案例:
Run Configuration
with option All in Module
and one with All in Package
All in Module
选项创建AndroidTest Run Configuration
,使用All in Package
创建一个 All in Package
: Test passed All in Package
运行:测试通过 All in Module
: No tests were found All in Module
使用All in Module
运行:未找到任何测试 Running with All in Module
worked fine until a few days ago. 使用
All in Module
运行直到几天前一直运行良好。 The changes I recall having made are upgrading Android Studio to 1.4 and upgrading Android Support Library
to 23.1.0 and Android Support Repository
to 24.0.0. 我记得有所做的更改正在升级的Android工作室1.4和升级
Android Support Library
到23.1.0和Android Support Repository
到24.0.0。
Btw. 顺便说一句。 also
gradlew connectedCheck
and gradlew createDebugAndroidTestCoverageReport
fail now. 还有
gradlew connectedCheck
和gradlew createDebugAndroidTestCoverageReport
现在失败了。
Does anyone have suggestions to solve this issue? 有没有人有解决这个问题的建议?
build.gradle for app: app.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'
}
}
Test.java Test.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() {
}
}
Trace in Run window: 在运行窗口中跟踪:
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: No susceptible differences found. logcat:没有发现易感差异。
Switching from emulator based on API 10 to API 17 fixed the issue. 从基于API 10的仿真器切换到API 17解决了该问题。
Although API 10 was running fine until last week, it has become unpredictable. 尽管API 10在上周运行良好,但它已变得无法预测。 Sometimes it runs, mostly it doesn't.
有时它会运行,但大多数情况下都没有。 Removing a single test method might make it work, and placing it back might keep it working (or not).
删除单个测试方法可能会使其工作,将其放回可能会使其保持工作(或不工作)。 Trying to run the test for the fifth time might make it work again...
试图第五次运行测试可能会再次运行...
UPDATE 2016-03-16 : Increasing the resources for the API 10 emulator made the test available for API 10 again... 更新2016-03-16 :增加API 10仿真器的资源使测试再次可用于API 10 ...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.