简体   繁体   English

Robolectric测试未针对具有自己的Application类的项目运行

[英]Robolectric test not running for project having own Application class

I have followed steps as mentioned Robolectric http://robolectric.org/eclipse-quick-start/ I am able to successfully run the test as per steps provided. 我遵循了Robolectric所说的步骤http://robolectric.org/eclipse-quick-start/我能够按照提供的步骤成功运行测试。 For a fresh new Project and Test project. 对于一个新的新项目和测试项目。

But when I followed same steps for my existing project, then nothing happens only a warning is being shown and test gets terminated. 但是,当我对现有项目执行相同的步骤时,什么也没有发生,只显示警告并终止测试。

在此处输入图片说明

My existing app is for target android-15 and I am using robolectric-2.2-jar-with-dependencies.jar 我现有的应用是针对目标android-15的,并且我正在使用robolectric-2.2-jar-with-dependencies.jar

PS I have created a new Java Project for my existing project. PS我为现有项目创建了一个新的Java项目。

UPDATE 更新

After hours of debugging I found that, if I remove android:name="com.myapp.bl.MyApplication from AndroidManifest, then its starts executing tests. 经过数小时的调试,我发现,如果我从AndroidManifest中删除了android:name="com.myapp.bl.MyApplication ,则它将开始执行测试。

<application
    android:name="com.myapp.bl.MyApplication" 
    android:allowBackup="false"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

Is there any addition flag or setting, that I have to pass Robolectric, so that it understands MyApplication class. 是否有任何其他标志或设置,我必须通过Robolectric,以便它理解MyApplication类。

Regards, Yuvi 问候,尤维

I found the issue, there was an exception in MyApplication class. 我发现了问题,MyApplication类中有一个异常。 If that exception occurs then application was getting closed. 如果发生该异常,则说明应用程序已关闭。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Robolectric测试Application类? - How to test Application class with Robolectric? 运行多个测试时,Robolectric会忽略自定义和测试应用程序类 - Robolectric ignores custom and test application class when running more than one test Robolectric不使用测试应用程序 - Robolectric not using test application Robolectric:如何测试内部使用应用程序实例的类? - Robolectric: how to test class which use application instance inside? MultiDexApplication的使用导致Application类的Robolectric测试中断 - Usage of MultiDexApplication causes Robolectric test for the Application class to break 如何使用robolectric测试应用程序类中的方法? - How do I test methods in the application class with robolectric? 使用Dagger和Robolectric进行测试应用 - Using Dagger and Robolectric with test application Android Robolectric Library类支持。 如何从应用程序项目加载库类R引用 - Android Robolectric Library class support. How to have library class R references load from application project Robolectric-Gradle插件运行单个测试 - Robolectric-Gradle plugin running single test 使用Robolectric和AppCompat运行Gradle测试会导致NullPointerException - Running Gradle test with Robolectric and AppCompat results in NullPointerException
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM