2013-08-26 9 views
20

Sto provando a impostare un test utilizzando Robolectric per fare clic su un pulsante di menu in this repository. Verranno eseguiti i test di base di Robolectric, ma non sono in grado di eseguire alcun test specifico del progetto utilizzando le risorse perché dice che non è possibile trovare il mio AndroidManifest.xml. Dopo aver eseguito ../gradlew clean check, ecco l'output standard dal file html Robolectric:Gradle + Robolectric: dove inserisco il file org.robolectric.Config.properties?

WARNING: No manifest file found at ./AndroidManifest.xml.Falling back to the Android OS resources only. To remove this warning, annotate your test class with @Config(manifest=Config.NONE).

ho trovato these instructions che indicano dovrei creare un file org.robolectric.Config.properties, ma non sono sicuro dove metterlo. Ho provato ovunque, praticamente, e nonostante lo spostamento del file, il percorso nel messaggio di errore è sempre lo stesso di sopra (./AndroidManifest.xml). Questo mi fa pensare che il processo di compilazione non abbia mai rilevato le impostazioni nel file org.robolectric.Config.properties.

Ho anche provato la direttiva @Config (manifest = "") ma questo mi ha dato un errore cannot find symbol. Se sposto AndroidManifest.xml nella mia directory di progetto, ricevo un errore in quanto non riesco a trovare il percorso ./res/values e non sono riuscito a risolvere neanche questo. Qualche idea?

Update 1

Grazie Eugen, ora sto usando @RunWith(RobolectricGradleTestRunner.class) invece di @RunWith(RobolectricTestRunner).

Ora ottengo un errore diverso, ancora si verificano sulla stessa linea di my BasicTest.java

KeywordList keywordList = Robolectric.buildActivity(KeywordList.class).create().get(); 

Qui di seguito sono i risultati da l'errore standard, standard output e scheda "test fallito" nel verbale di prova Robolectric:

Nota: ho anche provato a sostituire in un jar creato dagli ultimi aggiornamenti di Robolectric, robolectric-2.2-SNAPSHOT.jar, ma ho ancora ricevuto un errore.

Errore standard

WARNING: no system properties value for ro.build.date.utc

uscita standard

DEBUG: Loading resources for net.frontlinesms.android from ~/workspace-studio/frontlinesms-for-android/FrontlineSMS/build/res/all/debug... 
DEBUG: Loading resources for android from jar:~/.m2/repository/org/robolectric/android-res/4.1.2_r1_rc/android-res-4.1.2_r1_rc-real.jar!/res... 
INFO: no id mapping found for android:drawable/scrollbar_handle_horizontal; assigning ID #0x1140002 
INFO: no id mapping found for android:drawable/scrollbar_handle_vertical; assigning ID #0x1140003 
INFO: no id mapping found for android:color/highlighted_text_dark; assigning ID #0x1140004 
INFO: no id mapping found for android:color/hint_foreground_dark; assigning ID #0x1140005 
INFO: no id mapping found for android:color/link_text_dark; assigning ID #0x1140006 
INFO: no id mapping found for android:color/dim_foreground_dark_disabled; assigning ID #0x1140007 
INFO: no id mapping found for android:color/dim_foreground_dark; assigning ID #0x1140008 
INFO: no id mapping found for android:color/dim_foreground_dark_inverse_disabled; assigning ID #0x1140009 
INFO: no id mapping found for android:color/dim_foreground_dark_inverse; assigning ID #0x114000a 
INFO: no id mapping found for android:color/bright_foreground_dark_inverse; assigning ID #0x114000b 
INFO: no id mapping found for android:layout/text_edit_paste_window; assigning ID #0x114000c 
INFO: no id mapping found for android:layout/text_edit_no_paste_window; assigning ID #0x114000d 
INFO: no id mapping found for android:layout/text_edit_side_paste_window; assigning ID #0x114000e 
INFO: no id mapping found for android:layout/text_edit_side_no_paste_window; assigning ID #0x114000f 
INFO: no id mapping found for android:layout/text_edit_suggestion_item; assigning ID #0x1140010 

test falliti

android.view.InflateException: XML file ~/workspace-studio/frontlinesms-for-android/FrontlineSMS/build/res/all/debug/layout/rule_list.xml line #-1 (sorry, not yet implemented): Error inflating class net.frontlinesms.android.ui.view.ActionBar 
at android.view.LayoutInflater.createView(LayoutInflater.java:613) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:489) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:396) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:352) 
at org.robolectric.tester.android.view.RoboWindow.setContentView(RoboWindow.java:82) 
at org.robolectric.shadows.ShadowActivity.setContentView(ShadowActivity.java:272) 
at android.app.Activity.setContentView(Activity.java) 
at net.frontlinesms.android.activity.KeywordList.onCreate(KeywordList.java:70) 
at android.app.Activity.performCreate(Activity.java:5008) 
at org.fest.reflect.method.Invoker.invoke(Invoker.java:112) 
at org.robolectric.util.ActivityController$1.run(ActivityController.java:119) 
at org.robolectric.shadows.ShadowLooper.runPaused(ShadowLooper.java:256) 
at org.robolectric.util.ActivityController.create(ActivityController.java:114) 
at org.robolectric.util.ActivityController.create(ActivityController.java:126) 
at net.frontlinesms.android.BasicTest.setUp(BasicTest.java:30) 
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47) 
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) 
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) 
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24) 
at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:241) 
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271) 
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70) 
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) 
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) 
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) 
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) 
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) 
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) 
at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:177) 
at org.junit.runners.ParentRunner.run(ParentRunner.java:309) 
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.runTestClass(JUnitTestClassExecuter.java:80) 
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.execute(JUnitTestClassExecuter.java:47) 
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassProcessor.processTestClass(JUnitTestClassProcessor.java:69) 
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:49) 
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35) 
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24) 
at org.gradle.messaging.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32) 
at org.gradle.messaging.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93) 
at com.sun.proxy.$Proxy2.processTestClass(Unknown Source) 
at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:103) 
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35) 
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24) 
at org.gradle.messaging.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:355) 
at org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:66) 
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918) 
at java.lang.Thread.run(Thread.java:680) 
Caused by: java.lang.reflect.InvocationTargetException 
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) 
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) 
at java.lang.reflect.Constructor.newInstance(Constructor.java:513) 
at android.view.LayoutInflater.$$robo$$LayoutInflater_1d1f_createView(LayoutInflater.java:587) 
at android.view.LayoutInflater.createView(LayoutInflater.java) 
at android.view.LayoutInflater.$$robo$$LayoutInflater_1d1f_createViewFromTag(LayoutInflater.java:687) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java) 
at android.view.LayoutInflater.$$robo$$LayoutInflater_1d1f_rInflate(LayoutInflater.java:746) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java) 
at android.view.LayoutInflater.$$robo$$LayoutInflater_1d1f_inflate(LayoutInflater.java:489) 
at android.view.LayoutInflater.inflate(LayoutInflater.java) 
at android.view.LayoutInflater.$$robo$$LayoutInflater_1d1f_inflate(LayoutInflater.java:396) 
at android.view.LayoutInflater.inflate(LayoutInflater.java) 
at android.view.LayoutInflater.$$robo$$LayoutInflater_1d1f_inflate(LayoutInflater.java:352) 
at android.view.LayoutInflater.inflate(LayoutInflater.java) 
at org.robolectric.tester.android.view.RoboWindow.setContentView(RoboWindow.java:82) 
at org.robolectric.shadows.ShadowActivity.setContentView(ShadowActivity.java:272) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
at java.lang.reflect.Method.invoke(Method.java:597) 
at org.robolectric.bytecode.ShadowWrangler$ShadowMethodPlan.run(ShadowWrangler.java:455) 
at android.app.Activity.setContentView(Activity.java) 
at net.frontlinesms.android.activity.KeywordList.onCreate(KeywordList.java:70) 
at android.app.Activity.$$robo$$Activity_c57b_performCreate(Activity.java:5008) 
at android.app.Activity.performCreate(Activity.java) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
at java.lang.reflect.Method.invoke(Method.java:597) 
at org.fest.reflect.method.Invoker.invoke(Invoker.java:112) 
at org.robolectric.util.ActivityController$1.run(ActivityController.java:119) 
at org.robolectric.shadows.ShadowLooper.runPaused(ShadowLooper.java:256) 
at org.robolectric.util.ActivityController.create(ActivityController.java:114) 
at org.robolectric.util.ActivityController.create(ActivityController.java:126) 
at net.frontlinesms.android.BasicTest.setUp(BasicTest.java:30) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
at java.lang.reflect.Method.invoke(Method.java:597) 
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47) 
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) 
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) 
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24) 
at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:241) 
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271) 
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70) 
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) 
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) 
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) 
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) 
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) 
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) 
at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:177) 
at org.junit.runners.ParentRunner.run(ParentRunner.java:309) 
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.runTestClass(JUnitTestClassExecuter.java:80) 
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.execute(JUnitTestClassExecuter.java:47) 
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassProcessor.processTestClass(JUnitTestClassProcessor.java:69) 
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:49) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
at java.lang.reflect.Method.invoke(Method.java:597) 
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35) 
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24) 
at org.gradle.messaging.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32) 
at org.gradle.messaging.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93) 
at com.sun.proxy.$Proxy2.processTestClass(Unknown Source) 
at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:103) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
at java.lang.reflect.Method.invoke(Method.java:597) 
... 7 more 
Caused by: android.view.InflateException: XML file ~/workspace-studio/frontlinesms-for-android/FrontlineSMS/build/res/all/debug/layout/actionbar.xml line #-1 (sorry, not yet implemented): Error inflating class android.widget.ProgressBar 
at android.view.LayoutInflater.createView(LayoutInflater.java:613) 
at org.robolectric.shadows.RoboLayoutInflater.onCreateView(RoboLayoutInflater.java:38) 
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:749) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:489) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:396) 
at net.frontlinesms.android.ui.view.ActionBar.<init>(ActionBar.java:65) 
at android.view.LayoutInflater.createView(LayoutInflater.java:587) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:489) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:396) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:352) 
at org.robolectric.tester.android.view.RoboWindow.setContentView(RoboWindow.java:82) 
at org.robolectric.shadows.ShadowActivity.setContentView(ShadowActivity.java:272) 
at android.app.Activity.setContentView(Activity.java) 
at net.frontlinesms.android.activity.KeywordList.onCreate(KeywordList.java:70) 
at android.app.Activity.performCreate(Activity.java:5008) 
at org.fest.reflect.method.Invoker.invoke(Invoker.java:112) 
at org.robolectric.util.ActivityController$1.run(ActivityController.java:119) 
at org.robolectric.shadows.ShadowLooper.runPaused(ShadowLooper.java:256) 
at org.robolectric.util.ActivityController.create(ActivityController.java:114) 
at org.robolectric.util.ActivityController.create(ActivityController.java:126) 
at net.frontlinesms.android.BasicTest.setUp(BasicTest.java:30) 
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47) 
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) 
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) 
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24) 
at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:241) 
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271) 
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70) 
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) 
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) 
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) 
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) 
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) 
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) 
at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:177) 
at org.junit.runners.ParentRunner.run(ParentRunner.java:309) 
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.runTestClass(JUnitTestClassExecuter.java:80) 
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.execute(JUnitTestClassExecuter.java:47) 
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassProcessor.processTestClass(JUnitTestClassProcessor.java:69) 
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:49) 
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35) 
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24) 
at org.gradle.messaging.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32) 
at org.gradle.messaging.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93) 
at com.sun.proxy.$Proxy2.processTestClass(Unknown Source) 
at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:103) 
... 7 more 
Caused by: java.lang.reflect.InvocationTargetException 
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) 
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) 
at java.lang.reflect.Constructor.newInstance(Constructor.java:513) 
at android.view.LayoutInflater.$$robo$$LayoutInflater_1d1f_createView(LayoutInflater.java:587) 
at android.view.LayoutInflater.createView(LayoutInflater.java) 
at org.robolectric.shadows.RoboLayoutInflater.onCreateView(RoboLayoutInflater.java:38) 
at android.view.LayoutInflater.$$robo$$LayoutInflater_1d1f_onCreateView(LayoutInflater.java:660) 
at android.view.LayoutInflater.onCreateView(LayoutInflater.java) 
at android.view.LayoutInflater.$$robo$$LayoutInflater_1d1f_createViewFromTag(LayoutInflater.java:685) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java) 
at android.view.LayoutInflater.$$robo$$LayoutInflater_1d1f_rInflate(LayoutInflater.java:746) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java) 
at android.view.LayoutInflater.$$robo$$LayoutInflater_1d1f_rInflate(LayoutInflater.java:749) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java) 
at android.view.LayoutInflater.$$robo$$LayoutInflater_1d1f_inflate(LayoutInflater.java:489) 
at android.view.LayoutInflater.inflate(LayoutInflater.java) 
at android.view.LayoutInflater.$$robo$$LayoutInflater_1d1f_inflate(LayoutInflater.java:396) 
at android.view.LayoutInflater.inflate(LayoutInflater.java) 
at net.frontlinesms.android.ui.view.ActionBar.<init>(ActionBar.java:65) 
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) 
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) 
at java.lang.reflect.Constructor.newInstance(Constructor.java:513) 
at android.view.LayoutInflater.$$robo$$LayoutInflater_1d1f_createView(LayoutInflater.java:587) 
at android.view.LayoutInflater.createView(LayoutInflater.java) 
at android.view.LayoutInflater.$$robo$$LayoutInflater_1d1f_createViewFromTag(LayoutInflater.java:687) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java) 
at android.view.LayoutInflater.$$robo$$LayoutInflater_1d1f_rInflate(LayoutInflater.java:746) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java) 
at android.view.LayoutInflater.$$robo$$LayoutInflater_1d1f_inflate(LayoutInflater.java:489) 
at android.view.LayoutInflater.inflate(LayoutInflater.java) 
at android.view.LayoutInflater.$$robo$$LayoutInflater_1d1f_inflate(LayoutInflater.java:396) 
at android.view.LayoutInflater.inflate(LayoutInflater.java) 
at android.view.LayoutInflater.$$robo$$LayoutInflater_1d1f_inflate(LayoutInflater.java:352) 
at android.view.LayoutInflater.inflate(LayoutInflater.java) 
at org.robolectric.tester.android.view.RoboWindow.setContentView(RoboWindow.java:82) 
at org.robolectric.shadows.ShadowActivity.setContentView(ShadowActivity.java:272) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
at java.lang.reflect.Method.invoke(Method.java:597) 
at org.robolectric.bytecode.ShadowWrangler$ShadowMethodPlan.run(ShadowWrangler.java:455) 
at android.app.Activity.setContentView(Activity.java) 
at net.frontlinesms.android.activity.KeywordList.onCreate(KeywordList.java:70) 
at android.app.Activity.$$robo$$Activity_c57b_performCreate(Activity.java:5008) 
at android.app.Activity.performCreate(Activity.java) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
at java.lang.reflect.Method.invoke(Method.java:597) 
at org.fest.reflect.method.Invoker.invoke(Invoker.java:112) 
at org.robolectric.util.ActivityController$1.run(ActivityController.java:119) 
at org.robolectric.shadows.ShadowLooper.runPaused(ShadowLooper.java:256) 
at org.robolectric.util.ActivityController.create(ActivityController.java:114) 
at org.robolectric.util.ActivityController.create(ActivityController.java:126) 
at net.frontlinesms.android.BasicTest.setUp(BasicTest.java:30) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
at java.lang.reflect.Method.invoke(Method.java:597) 
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47) 
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) 
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) 
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24) 
at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:241) 
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271) 
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70) 
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) 
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) 
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) 
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) 
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) 
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) 
at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:177) 
at org.junit.runners.ParentRunner.run(ParentRunner.java:309) 
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.runTestClass(JUnitTestClassExecuter.java:80) 
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.execute(JUnitTestClassExecuter.java:47) 
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassProcessor.processTestClass(JUnitTestClassProcessor.java:69) 
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:49) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
at java.lang.reflect.Method.invoke(Method.java:597) 
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35) 
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24) 
at org.gradle.messaging.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32) 
at org.gradle.messaging.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93) 
at com.sun.proxy.$Proxy2.processTestClass(Unknown Source) 
at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:103) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
at java.lang.reflect.Method.invoke(Method.java:597) 
... 7 more 
Caused by: java.lang.ClassCastException: org.robolectric.res.AttrData cannot be cast to org.robolectric.res.StyleData 
at org.robolectric.shadows.ShadowAssetManager$StyleResolver.getParent(ShadowAssetManager.java:353) 
at org.robolectric.shadows.ShadowAssetManager$StyleResolver.getAttrValue(ShadowAssetManager.java:336) 
at org.robolectric.shadows.ShadowResources.findAttributeValue(ShadowResources.java:259) 
at org.robolectric.shadows.ShadowResources.attrsToTypedArray(ShadowResources.java:188) 
at org.robolectric.shadows.ShadowResources.access$000(ShadowResources.java:51) 
at org.robolectric.shadows.ShadowResources$ShadowTheme.obtainStyledAttributes(ShadowResources.java:460) 
at android.content.res.Resources$Theme.obtainStyledAttributes(Resources.java) 
at android.content.Context.obtainStyledAttributes(Context.java:374) 
at android.view.View.__constructor__(View.java:3297) 
at org.fest.reflect.method.Invoker.invoke(Invoker.java:112) 
at org.robolectric.shadows.ShadowView.__constructor__(ShadowView.java:68) 
at android.view.View.<init>(View.java:3295) 
at android.widget.ProgressBar.<init>(ProgressBar.java:253) 
at android.widget.ProgressBar.<init>(ProgressBar.java:246) 
at android.widget.ProgressBar.<init>(ProgressBar.java:242) 
at android.view.LayoutInflater.createView(LayoutInflater.java:587) 
at org.robolectric.shadows.RoboLayoutInflater.onCreateView(RoboLayoutInflater.java:38) 
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:749) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:489) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:396) 
at net.frontlinesms.android.ui.view.ActionBar.<init>(ActionBar.java:65) 
at android.view.LayoutInflater.createView(LayoutInflater.java:587) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:489) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:396) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:352) 
at org.robolectric.tester.android.view.RoboWindow.setContentView(RoboWindow.java:82) 
[truncated, hit stack overflow character limit...] 
+0

ha avuto lo stesso problema, come hai risolto questo? –

+0

Ciao @VinceV. scusa, non ho trovato una soluzione. Ho accantonato questo lavoro e non ci sono ancora tornato. Per favore fatemi sapere se trovate una soluzione. –

+0

Ho fatto la stessa cosa. Aveva iniziato con pieno coraggio a utilizzare test in Android. Ma rinunciato. –

risposta

0

vedo che si sta seguendo questo: https://github.com/square/gradle-android-test-plugin

penso che si dovrebbe modificare la @RunWith(RobolectricTestRunner.class) al @RunWith(RobolectricGradleTestRunner.class)

+0

Grazie Eugen. Ora sto riscontrando un errore diverso, qualcosa su 'Errore durante l'inflazione della classe net.frontlinesms.android.ui.view.ActionBar'. Ho postato tutti gli output sotto ** Update 1 ** sopra –

+0

Non so come risolvere questo problema adesso –

+2

Nota che da Robolectric 3.1.1, RobolectricGradleTestRunner è deprecato e RobolectricTestRunner dovrebbe invece essere usato. Fonte: https://github.com/robolectric/robolectric/wiki/3.0-to-3.1-Upgrade-Guide –

3

Il percorso src/test/resources come detto sul blog Robolectric sembra funzionare per il file org.robolectric.Config.properties con il test plugin e Robolectric SNAPSHOTS. Il RobolectricGradleTestRunner non è più richiesto.

1

Sto usando il robolectric gradle plugin e ho affrontato (o sto ancora affrontando;) seri problemi con i test di junit in AS.

Tuttavia, una volta che ho appena scoperto è la posizione dello org.robolectric.Config.properties. Anch'io ho provato molti punti nel progetto sorgente, ma AS ha iniziato a prenderlo solo dopo averlo inserito in build/test-classes.

Si può avere uno sguardo al mio script di build Gradle a: Debug gradle-based unit tests with IntelliJ/AndroidStudio

Altre misure necessarie per farlo unit test in esecuzione in AS:

  1. riordinare l'<orderEntry type="jdk" ... /> alla fine della lista in il tuo file <app>.iml (questo serve ad evitare le eccezioni Stub !!, vedi: https://github.com/robolectric/deckard-gradle) - questo passo deve essere ripetuto ogni volta che si sincronizza con gradle.

  2. Aggiungere la cartella dei file di test compilati al file <app>.iml. Aggiungere <output-test url="file://$MODULE_DIR$/build/test-classes" /> subito dopo <output url=... /> (vedi: Android Studio + Robolectric + Gradle Class Not Found Exception)

  3. si compila app con Gradle: gradlew app:clean app:testDebug o qualcosa di simile. Ho notato che AS compila solo i file sorgente, ma in qualche modo non compila le classi di test, almeno non da nessuna parte nella cartella /build. Gradle invece compila correttamente le classi di test a /build/test-classes e con la configurazione nel passaggio 2) AS le preleva anche, una volta compilato. Ovviamente questo passaggio deve essere ripetuto ogni volta che si modificano le classi di test. (Nota: ho anche trovato un'altra soluzione da Eugen, vedi: https://stackoverflow.com/a/24140796/1406325 - non ho provato quella ancora, ma sembra che così facendo non richiede il passaggio aggiuntivo di compilare con Gradle)

  4. Metti la tua org.robolectric.Config.properties in /build/test-classes (poiché con il passaggio 2) AS lo raccoglierà ora.

  5. Se si dispone anche di riferimenti ad altre librerie, potrebbe essere necessario un file project.properties (ovvero se si riscontrano problemi Resources$NotFoundException durante l'esecuzione dei test). Di nuovo, dove mettere questo file? Si va in <app>/src/main (Vedi: https://groups.google.com/forum/#!topic/robolectric/gjpwqRICT5U)

     
    android.library.reference.1=../../../library/src/main 
    

Speranza che aiuta!

+0

Fare attenzione a inserire e conservare qualcosa nella cartella di creazione. La prima pulizia la cancellerà –

+0

Veramente, non è divertente da mantenere, eh. Questo è il primo approccio che ho trovato, ma sto ancora indagando, e aggiornerò questa risposta, nel caso trovassi una soluzione più semplice ... Altrimenti ci sarebbe ancora la possibilità di modificare l'attività gradle e di copiare gradualmente il file lì ogni volta che compila le sorgenti di test ... – Flo

1

Ho avuto la fortuna di mettere org.robolectric.Config.properties in src/test/res, ma non src/test/resources.

1

Il modo migliore è quello di ignorare getConfigProperties() in una sottoclasse di RobolectricTestRunner mettendo il file di proprietà in una cartella e specificando il percorso come segue:

@Override 
    protected Properties getConfigProperties() { 
     FsFile fs = Fs.currentDirectory(); 
     InputStream resourceAsStream = null; 
     try { 
      File f = new File(fs.getPath() + <location-to-file-from-root-dir> + <file-name>); 
      resourceAsStream = new FileInputStream(f); 
     } catch (Exception e) { 
      resourceAsStream = null; 
     } 
     if (resourceAsStream == null) return null; 
     Properties properties = new Properties(); 
     try { 
      properties.load(resourceAsStream); 
     } catch (IOException e) { 
      throw new RuntimeException(e); 
     } 
     return properties; 
    } 
6

ho finalmente trovato il posto giusto per metterlo. In primo luogo, la struttura della mia applicazione viene mostrata come di seguito:

la mia domanda è in fase di

app/src/main/ 

la mia applicazione di test è in fase di

app/src/test/ 

Si dovrebbe assegnare un nome al file di proprietà come robolectric.proprietà e metterla sotto

src/test/resources/ 

Il contenuto di robolectric.properties è

manifest: src/main/AndroidManifest.xml 

Poi, il programma di test può finalmente trovare il file di proprietà!

+0

robolectric.properties era sotto app/src/test/resources o solo src/test/risorse? – Ahmed

+1

app/src/test/resources – pptang

+1

Ho provato ma non ha funzionato con Robolectric ** 3.0 **. –