Android Espresso:“未找到测试" ,“进程崩溃" [英] Android Espresso: "No test were found" , "Process crashed"
问题描述
当用Espresso测试我的Android应用程序时,我注意到运行配置为All in Module
的AndroidTest找不到任何测试,而运行All in Package
则成功.
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.
我创建了以下可重复的案例:
I created the following reproducible case:
- 使用向导使用minSdk 8和空的Activity创建新的干净应用程序
- 配置gradle与espresso依赖项等(见下文)
- 使用选项
All in Module
创建AndroidTestRun Configuration
,并使用All in Package
创建一个
- 添加带有测试的课程(见下文)
- 使用
All in Package
运行:测试通过 - 使用
All in Module
运行:未找到测试
- Use wizard to create new clean application with minSdk 8 and empty Activity
- Configure gradle with espresso dependencies etc. (see below)
- Create AndroidTest
Run Configuration
with optionAll in Module
and one withAll in Package
- Add class with tests (see below)
- Run with
All in Package
: Test passed - Run with
All in Module
: No tests were found
使用All in Module
运行直到几天前都运行良好.我记得所做的更改是将Android Studio升级到1.4,并将Android Support Library
升级到23.1.0和Android Support Repository
升级到24.0.0.
Running with All in Module
worked fine until a few days ago. 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.
顺便说一句. gradlew connectedCheck
和gradlew createDebugAndroidTestCoverageReport
现在也失败了.
Btw. also gradlew connectedCheck
and gradlew createDebugAndroidTestCoverageReport
fail now.
有人建议解决此问题吗?
Does anyone have suggestions to solve this issue?
app的build.gradle:
build.gradle for app:
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() {
}
}
运行"窗口中的跟踪:
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:找不到敏感差异.
logcat: No susceptible differences found.
推荐答案
从基于API 10的仿真器切换到API 17可以解决此问题.
Switching from emulator based on API 10 to API 17 fixed the issue.
尽管API 10直到上周都运行良好,但是它变得不可预测.有时它会运行,但大多数情况下不会.删除单个测试方法可能会使它起作用,而将其放回原处可能会使它起作用(或不起作用).尝试第五次运行测试可能会使它再次工作...
Although API 10 was running fine until last week, it has become unpredictable. 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...
更新2016-03-16 : 用于API 10仿真器的资源的增加使该测试再次可用于API 10 ...
UPDATE 2016-03-16: Increasing the resources for the API 10 emulator made the test available for API 10 again...
这篇关于Android Espresso:“未找到测试" ,“进程崩溃"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!