Robolectric 2.0 не создает представления при тестировании

Я пытаюсь настроить тестирование с помощью robolectric и roboguice. Я успешно внедряю и тестирую классы, но когда я пытаюсь протестировать действия, я не могу создать объекты View в тестовой среде.

Я получаю следующие ошибки

нашел проблему. Robolectric не понравились параметры времени Android, установленные в моем пароле EditText. Как только я удалил эти строки, тест запустился, как и ожидалось.


person David    schedule 05.06.2013    source источник


Ответы (2)


У меня были похожие ошибки, но проблема была _1_, а не _2_. Удаление _3_ из XML и установка его в коде (но сохранение _4_) решили эту проблему.

person David    schedule 05.06.2013
comment
testAttemptsLoginWhenSignInButtonIsClicked(com.clearc2.HomeActivityTest) Истекшее время: 2,234 сек ‹‹‹ ОШИБКА! java.lang.RuntimeException: не удалось создать android.widget.EditText в org.robolectric.res.builder.LayoutBuilder.constructView(LayoutBuilder.java:182) в org.robolectric.res.builder.LayoutBuilder.create(LayoutBuilder.java :109) на org.robolectric.res.builder.LayoutBuilder.doInflate(LayoutBuilder.java:42) на org.robolectric.res.builder.LayoutBuilder.doInflate(LayoutBuilder.java:45) на org.robolectric.res.builder. LayoutBuilder.doInflate(LayoutBuilder.java:45) в org.robolectric.res.builder.LayoutBuilder.doInflate(LayoutBuilder.java:45) в org.robolectric.res.builder.LayoutBuilder.inflateView(LayoutBuilder.java:62) в org .robolectric.shadows.ShadowLayoutInflater.inflate(ShadowLayoutInflater.java:50) в org.robolectric.shadows.ShadowLayoutInflater.inflate(ShadowLayoutInflater.java:55) в android.view.LayoutInflater.inflate(LayoutInflater.java) в org.robolectric. tester.android.view.RoboWindow.setContentView(RoboWindow.java:8 0) в org.robolectric.shadows.ShadowActivity.setContentView(ShadowActivity.java:265) в android.app.Activity.setContentView(Activity.java) в com.clearc2.HomeActivity.onCreate(HomeActivity.java:38) в com. clearc2.HomeActivityTest.setUp(HomeActivityTest.java:22) в org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44) в org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java :15) в org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41) в org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27) в org.junit.internal. runners.statements.RunAfters.evaluate(RunAfters.java:31) в org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:246) в org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79) в org. junit.runners.BlockJUnit4ClassRunner.runChild (BlockJUnit4ClassRunner.java :71) в org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49) в org.junit.runners.ParentRunner$3.run(ParentRunner.java:193) в org.junit.runners.ParentRunner$1.schedule( ParentRunner.java:52) в org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191) в org.junit.runners.ParentRunner.access$000(ParentRunner.java:42) в org.junit.runners. ParentRunner$2.evaluate(ParentRunner.java:184) в org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:181) в org.junit.runners.ParentRunner.run(ParentRunner.java:236) в org.apache.maven .surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:59) в org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:120) в org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute (AbstractDirectoryTestSuite.java:103) по адресу org.apache.maven.surefire.Surefire.run(Surefire.java:169) по адресу org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:350) по адресу org. apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1021) Вызвано: java.lang.reflect.InvocationTargetException в sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) в sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl .j ava:57) в sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) в java.lang.reflect.Constructor.newInstance(Constructor.java:525) в org.robolectric.res.builder.LayoutBuilder.constructView(LayoutBuilder .java:167) на org.robolectric.res.builder.LayoutBuilder.create(LayoutBuilder.java:109) на org.robolectric.res.builder.LayoutBuilder.doInflate(LayoutBuilder.java:42) на org.robolectric.res. builder.LayoutBuilder.doInflate(LayoutBuilder.java:45) в org.robolectric.res.builder.LayoutBuilder.doInflate(LayoutBuilder.java:45) в org.robolectric.res.builder.LayoutBuilder.doInflate(LayoutBuilder.java:45) на org.robolectric.res.builder.LayoutBuilder.inflateView(LayoutBuilder.java:62) на org.robolectric.shadows.ShadowLayoutInflater.inflate(ShadowLayoutInflater.java:50) на org.robolectric.shadows.ShadowLayoutInflater.inflate(ShadowLayoutInflater.java :55) на sun.reflect.NativeMethodAcc essorImpl.invoke0(собственный метод) в sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) в sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) в java.lang.reflect.Method.invoke(Method. java:601) в org.robolectric.bytecode.ShadowWrangler$ShadowMethodPlan.run(ShadowWrangler.java:440) в android.view.LayoutInflater.inflate(LayoutInflater.java) в org.robolectric.tester.android.view. RoboWindow.setContentView(RoboWindow.java:80) в org.robolectric.shadows.ShadowActivity.setContentView(ShadowActivity.java:265) в sun.reflect.NativeMethodAccessorImpl.invoke0(собственный метод) в sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl. java:57) в sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) в java.lang.reflect.Method.invoke(Method.java:601) в org.robolectric.bytecode.ShadowWrangler$ShadowMethodPlan.run(ShadowWrangler) .java:440) в android.app.Activity.setContentView(Activity.java) в com.clearc2.HomeActivity.onCreate(HomeActivity.java:38) в com.clearc2.HomeActivityTest.setUp(HomeActivityTest.java:22) в солнце .reflect.NativeMethodAccessorImpl.invoke0(собственный метод) в sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) в sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) в java.lang.reflect.Method.in voke(Method.java:601) в org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44) в org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) в org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41) в org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27) в org.junit.internal.runners.statements. RunAfters.evaluate(RunAfters.java:31) в org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:246) в org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79) в org.junit.runners. BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71) в org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49) в org.junit.runners.ParentRunner$3.run(ParentRunner.java:193) в org.junit. runners.ParentRunner$1.schedule(ParentRunner.java:52) на org.junit.runne rs.ParentRunner.runChildren(ParentRunner.java:191) в org.junit.runners.ParentRunner.access$000(ParentRunner.java:42) в org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184) в org .robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:181) в org.junit.runners.ParentRunner.run(ParentRunner.java:236) в org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java: 59) на org.apache.maven.surefire.suite. AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:120) в org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:103) в org.apache.maven.surefire.Surefire.run(Surefire.java:169) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method .invoke(Method.java:601) ... еще 2 Вызвано: java.lang.NumberFormatException: Для входной строки: "@0" в java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) в java.lang .Integer.parseInt(Integer.java:492) в com.android.internal.util.XmlUtils.convertValueToInt(XmlUtils.java:123) в android.content.res.TypedArray.getInt(TypedArray.java:254) в android. widget.TextView.конструктор(TextView.j ava:827) в android.widget.TextView.(TextView.java:447) в android.widget.EditText.(EditText.java:60) в android.widget.EditText.(EditText.java:56) в org.robolectric .res.builder.LayoutBuilder.constructView(LayoutBuilder.java:167) в org.robolectric.res.builder.LayoutBuilder.create(LayoutBuilder.java:109) в org.robolectric.res.builder.LayoutBuilder.doInflate(LayoutBuilder.java :42) на org.robolectric.res.builder.LayoutBuilder.doInflate(LayoutBuilder.java:45) на org.robolectric.res.builder.LayoutBuilder.doInflate(LayoutBuilder.java:45) на org.robolectric.res.builder. LayoutBuilder.doInflate(LayoutBuilder.java:45) в org.robolectric.res.builder.LayoutBuilder.inflateView(LayoutBuilder.java:62) в org.robolectric.shadows.ShadowLayoutInflater.inflate(ShadowLayoutInflater.java:50) в org.robolectric .shadows.ShadowLayoutInflater.inflate(ShadowLayoutInflater.java:55) в android.view.LayoutInflater.inflate(LayoutInflater.java) в org.robolectric.tester.android.view.RoboWindow.setContentView(RoboWindow.java:80) в org.robolectric.shadows.ShadowActivity.setContentView(ShadowActivity.java:265) в android.app.Activity.setContentView(Activity.java ) в com.clearc2.HomeActivity.onCreate(HomeActivity.java:38) в com.clearc2.HomeActivityTest.setUp(HomeActivityTest.java:22) в org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44) ) на сайте org.junit.internal.runners.model. ReflectiveCallable.run(ReflectiveCallable.java:15) в org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41) в org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27) в org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31) в org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:246) в org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner. java:79) в org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71) в org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49) в org.junit.runners.ParentRunner$3.run( ParentRunner.java:193) в org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52) в org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191) в org.junit.runners.ParentRunner. доступ $ 000 (ParentRunner.java: 42) в org.junit.runners.ParentRun ner$2.evaluate(ParentRunner.java:184) в org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:181) в org.junit.runners.ParentRunner.run(ParentRunner.java:236) в org.apache.maven .surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:59) в org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:120) в org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute (AbstractDirectoryTestSuite.java:103) на org.apache.maven.surefire.Surefire.run(Surefire.java:169) ... еще 2 - person Alexandre Martins; 24.10.2014

Вот мои ошибки для справки и для поисковых роботов, чтобы людям было легче найти этот ответ:

Я предполагаю, что Robolectric по какой-то причине не может правильно проанализировать imeActionId. Похоже, это связано с проблемой, описанной в этом вопросе: Почему установка imeActionId с предопределенным ресурсом ID создает ошибку?

android.view.InflateException: XML file app/build/intermediates/res/debug/layout/fragment_registration_form.xml 
line #-1 (sorry, not yet implemented): Error inflating class com.company.project.widgets.MyCustomEditTextView
...
Caused by: java.lang.reflect.InvocationTargetException
...
Caused by: java.lang.NumberFormatException: For input string: "@0"
...

Это правильный ответ, и это очень помогло мне. Так что спасибо. И не забудьте отметить его как правильный ответ. Ваше здоровье.

person p4sh4    schedule 03.12.2014