Android 意式浓缩咖啡不';不能使用NineodelRoids动画?

Android 意式浓缩咖啡不';不能使用NineodelRoids动画?,android,android-testing,android-espresso,Android,Android Testing,Android Espresso,我正在尝试测试我的活动(HomeActivity),它有基于Nineodandroids lib和浓缩咖啡的重复动画。我关闭了系统动画(如上所述),但它没有帮助,我得到了一个错误(见下文)。唯一有帮助的是手动删除动画。 所以问题是我是否需要手动关闭动画(使用BuildConfig似乎没有任何麻烦),或者可能我做错了什么? 提前谢谢你 java.lang.RuntimeException: Could not launch intent Intent { act=android.intent.

我正在尝试测试我的活动(HomeActivity),它有基于Nineodandroids lib和浓缩咖啡的重复动画。我关闭了系统动画(如上所述),但它没有帮助,我得到了一个错误(见下文)。唯一有帮助的是手动删除动画。 所以问题是我是否需要手动关闭动画(使用BuildConfig似乎没有任何麻烦),或者可能我做错了什么? 提前谢谢你

 java.lang.RuntimeException: Could not launch intent Intent {
 act=android.intent.action.MAIN flg=0x14000000
 cmp=com.package.en/com.package.ui.HomeActivity } within 45 seconds.
 Perhaps the main thread has not gone idle within a reasonable amount
 of time? There could be an animation or something constantly
 repainting the screen. Or the activity is doing network calls on
 creation? See the threaddump logs. For your reference the last time
 the event queue was idle before your activity launch request was
 1392052899081 and and now the last time the queue went idle was:
 1392052899081. If these numbers are the same your activity might be hogging the event 
 queue.

我对9olddroids了解不多,但对于浓缩咖啡,你应该禁用动画,以便你的测试变得可靠,你可能已经做到了

因此,也许这就是通过添加一些禁用动画的代码来提高应用程序“可测试性”的情况。例如,您的活动可以有一种禁用动画的方法,如:

 public void disableAnimations() {
     this.mAnimationsEnabled = false;
 }
在每个动画之前,检查它们是否已启用。测试开始后,将禁用动画:

 public void setUp () {
    super.setUp();
     YourActivity activity = getActivity();
     activity.disableAnimations();
 }

 public void testXYZ() {
     // your test code
 }
我希望这能起作用,因为9OldDroids将停止干扰Espresso

解决问题:

@之前
public void setUp()引发异常{
super.setUp();
injectInstrumentation(InstrumentationRegistry.getInstrumentation());
Intent=getIntent();
if(intent==null){
intent=新intent();
}
intent.addFlags(intent.FLAG\u ACTIVITY\u CLEAR\u TOP);
intent.addFlags(intent.FLAG\u活动\u无\u动画);
setActivityIntent(intent);
}
@SuppressLint(“新API”)
@凌驾
公共活动{
最终T活动=super.getActivity();
activity.overridePendingTransition(0,0);
返回活动;

}
谢谢您的建议。我认为GoogleInstrumentationTestRunner在系统级别上处理它实际上不,您必须在模拟器上禁用动画或以编程方式(使用库存动画)禁用动画。现在我认为这在使用第三方图书馆时尤其正确。这对你有用吗?我用了一点不同的方法,但主要思想是一样的。问题是如果你有复杂的动画和监听器,它需要很多样板代码,等等。我会等几天,如果没有人建议更好的解决方案,我接受你的回答。我只是使用BuildConfig.DEBUG在调试模式下关闭动画。必须向应用程序中添加仅用于测试的代码是非常糟糕的。这是一个秘密。考虑使用以避免使用弃用API和减少样板代码。