当使用Espresso测试我的Android应用程序时,我注意到运行配置为All in Module
的AndroidTest发现没有测试,而运行All in Package
成功。Android Espresso:“未发现测试”,“程序崩溃”
我创建了以下重现的情况下:
- 使用向导创建新的清洁应用与minSdk 8和空活动
- 与咖啡等依赖的gradle配置(见下文)
- 创建AndroidTest
Run Configuration
选项All in Module
和All in Package
- 添加测试类(参见下文)
- 以
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。
Btw。也gradlew connectedCheck
和gradlew 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'
}
}
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:未发现易感差异。
同样的情况也发生在我身上。是否有可能在模块中运行所有测试用例? – thedarkpassenger
@thedarkpassenger请参阅下面的答案。我增加了模拟器中的ram数量,并突然发挥作用...模块中定义的所有测试正在执行。 – passerby