Robolectric 单元测试没有响应
Roboelectric unit tests are unresponsive
我正在对我的 MVP Android 应用程序进行单元测试,但我无法 运行 在我的系统上进行 Roboelectric 单元测试。任何使用 Roboelectric 的测试都没有响应并永远挂起。
例如下面的测试永远 运行s:
import static com.google.common.truth.Truth.assert_;
@RunWith(RobolectricGradleTestRunner.class)
@Config(constants = BuildConfig.class, sdk = 23)
public class FakeTest {
@Test
public void testShouldFail() {
assert_().fail("Fail!");
}
}
Android Studio 只会在任何 Roboelectric 测试中无限期地显示一个旋转图标。 运行 终端中 gradle 的测试也挂起,但没有显示任何指示器。
这是我的 build.gradle
测试依赖项的样子:
// Unit testing
testCompile(
'junit:junit:4.12',
'org.mockito:mockito-core:1.10.19',
'com.google.truth:truth:0.28'
)
// Roboelectric 3.1-SNAPSHOT is the latest that supports API 23
testCompile('org.robolectric:robolectric:3.1-SNAPSHOT') {
exclude group: 'commons-logging'
exclude group: 'org.apache.httpcomponents'
}
系统信息:
OSX: 10.11.4
Android工作室:2.0.0-rc2
JDK: 1.8.0_40
Android SDK: 23
Gradle 工具:2.0.0-rc2
电动机器人:3.1-SNAPSHOT
Gradle: 2.10
我完全被难住了。 Roboelectric 没有调试输出表明有问题。任何帮助将不胜感激。
原来这个 https://github.com/frogermcs/AndroidDevMetrics gradle 插件与 Roboelectric 冲突。
对我来说,问题是 AndroidDevMetrics。如果您禁用 activiyMetrics,它可以正常工作。
AndroidDevMetrics.Builder androidDevMetricsBuilder =
new AndroidDevMetrics.Builder(this)
.enableActivityMetrics(!isRoboUnitTest())
.enableDagger2Metrics(true)
.showNotification(true);
AndroidDevMetrics.initWith(androidDevMetricsBuilder);
public static boolean isRoboUnitTest() {
return "robolectric".equals(Build.FINGERPRINT);
}
我正在对我的 MVP Android 应用程序进行单元测试,但我无法 运行 在我的系统上进行 Roboelectric 单元测试。任何使用 Roboelectric 的测试都没有响应并永远挂起。
例如下面的测试永远 运行s:
import static com.google.common.truth.Truth.assert_;
@RunWith(RobolectricGradleTestRunner.class)
@Config(constants = BuildConfig.class, sdk = 23)
public class FakeTest {
@Test
public void testShouldFail() {
assert_().fail("Fail!");
}
}
Android Studio 只会在任何 Roboelectric 测试中无限期地显示一个旋转图标。 运行 终端中 gradle 的测试也挂起,但没有显示任何指示器。
这是我的 build.gradle
测试依赖项的样子:
// Unit testing
testCompile(
'junit:junit:4.12',
'org.mockito:mockito-core:1.10.19',
'com.google.truth:truth:0.28'
)
// Roboelectric 3.1-SNAPSHOT is the latest that supports API 23
testCompile('org.robolectric:robolectric:3.1-SNAPSHOT') {
exclude group: 'commons-logging'
exclude group: 'org.apache.httpcomponents'
}
系统信息:
OSX: 10.11.4
Android工作室:2.0.0-rc2
JDK: 1.8.0_40
Android SDK: 23
Gradle 工具:2.0.0-rc2
电动机器人:3.1-SNAPSHOT
Gradle: 2.10
我完全被难住了。 Roboelectric 没有调试输出表明有问题。任何帮助将不胜感激。
原来这个 https://github.com/frogermcs/AndroidDevMetrics gradle 插件与 Roboelectric 冲突。
对我来说,问题是 AndroidDevMetrics。如果您禁用 activiyMetrics,它可以正常工作。
AndroidDevMetrics.Builder androidDevMetricsBuilder =
new AndroidDevMetrics.Builder(this)
.enableActivityMetrics(!isRoboUnitTest())
.enableDagger2Metrics(true)
.showNotification(true);
AndroidDevMetrics.initWith(androidDevMetricsBuilder);
public static boolean isRoboUnitTest() {
return "robolectric".equals(Build.FINGERPRINT);
}