我正在使用 Espresso 构建一些 ui 测试,一切正常,直到我访问应用程序中使用 RenderScript 模糊图像的 View 。
测试失败并出现错误:
java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
从我的谷歌搜索看来,发生这种情况是因为测试应用程序中有 2 个同一类的实例,并且大多数解决方案都暗示问题可能是 guava
库添加了两次。但这不是我的情况,因为它在实例化 RenderScript 的代码行上非常明显地失败了。
你有过类似的经历吗?我将不胜感激任何指导。
最佳答案
好的,所以我使用了一些技巧来解决这个问题。
黑客是在androidTest->java->com
中有一个标志类(可以为空)(位置并不特别,但作为androidTest
的一部分很重要>)。
类似这样的事情:
public class TestsRunningFlag {
}
然后有一个实用方法来检查是否可以加载该类。
/**
* A hacky way to determine whether the application is running normally,
* or as part of an instrumentation test.
*/
public static boolean isTestMode(Context context) {
boolean result;
try {
context.getClassLoader().loadClass("com.TestsRunningFlag");
result = true;
} catch (final Exception e) {
result = false;
}
return result;
}
然后根据我是否处于测试模式,我是否使用 RenderScript 来处理图像。
关于java - 由于 RenderScript,Android 仪器测试失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27965481/