2

更新到appcompat-v7:22.2.0之後,我的一些robolectric測試似乎失敗了。我使用appcompat-v7的Robolectric問題:22.2.0

支持庫:

compile 'com.android.support:support-v4:22.2.0' 
compile 'com.android.support:appcompat-v7:22.2.0' 
compile 'com.android.support:design:22.2.0' 

Robolectric庫

testCompile('org.robolectric:robolectric:3.0-rc3') 
testCompile('org.robolectric:shadows-support-v4:3.0-rc3') 

注:我的一切活動都延長AppCompatActivity。還使用新的谷歌設計庫中的NavigationView。

堆棧跟蹤:

android.view.InflateException: XML file ./../app/src/main/../../build/intermediates/exploded-aar/com.android.support/appcompat-v7/22.1.1/res/layout-v11/abc_screen_content_include.xml line #-1 (sorry, not yet implemented): Error inflating class android.support.v7.internal.widget.NativeActionModeAwareLayout 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:707) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755) 
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:814) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:745) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.inflate(CalligraphyLayoutInflater.java:60) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 
at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:321) 
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:246) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:106) 
at .HomeActivity_.setContentView(HomeActivity_.java:49) 
at .HomeActivity_.onCreate(HomeActivity_.java:39) 
at android.app.Activity.performCreate(Activity.java:5243) 
at org.robolectric.util.ReflectionHelpers.callInstanceMethod(ReflectionHelpers.java:195) 
at org.robolectric.util.ActivityController$1.run(ActivityController.java:122) 
at org.robolectric.shadows.ShadowLooper.runPaused(ShadowLooper.java:305) 
at org.robolectric.shadows.CoreShadowsAdapter$2.runPaused(CoreShadowsAdapter.java:45) 
at org.robolectric.util.ActivityController.create(ActivityController.java:118) 
at org.robolectric.util.ActivityController.create(ActivityController.java:129) 
at .HomeActivityTest.setUp(HomeActivityTest.java:43) 
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) 
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) 
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) 
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24) 
at org.powermock.modules.junit4.rule.PowerMockStatement$1.run(PowerMockRule.java:52) 
at org.powermock.reflect.internal.WhiteboxImpl.performMethodInvocation(WhiteboxImpl.java:1873) 
at org.powermock.reflect.internal.WhiteboxImpl.doInvokeMethod(WhiteboxImpl.java:773) 
at org.powermock.reflect.internal.WhiteboxImpl.invokeMethod(WhiteboxImpl.java:638) 
at org.powermock.reflect.Whitebox.invokeMethod(Whitebox.java:401) 
at org.powermock.classloading.ClassloaderExecutor.execute(ClassloaderExecutor.java:98) 
at org.powermock.classloading.ClassloaderExecutor.execute(ClassloaderExecutor.java:78) 
at org.powermock.modules.junit4.rule.PowerMockStatement.evaluate(PowerMockRule.java:49) 
at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:245) 
at org.robolectric.RobolectricTestRunner.runChild(RobolectricTestRunner.java:185) 
at org.robolectric.RobolectricTestRunner.runChild(RobolectricTestRunner.java:54) 
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) 
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) 
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) 
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) 
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) 
at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:149) 
at org.junit.runners.ParentRunner.run(ParentRunner.java:363) 
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.runTestClass(JUnitTestClassExecuter.java:86) 
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.execute(JUnitTestClassExecuter.java:49) 
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassProcessor.processTestClass(JUnitTestClassProcessor.java:69) 
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:48) 
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:105) 
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:360) 
at org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:64) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) 
at java.lang.Thread.run(Thread.java:745) 
Caused by: java.lang.ClassNotFoundException: android.support.v7.internal.widget.NativeActionModeAwareLayout 
    at org.robolectric.internal.bytecode.InstrumentingClassLoader.loadClass(InstrumentingClassLoader.java:87) 
    at android.view.LayoutInflater.createView(LayoutInflater.java:559) 
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696) 
    ... 59 more 

回答

1

如果按照這個指南http://nenick-android.blogspot.de/2015/02/android-studio-110-beta-4-and.html你有test-project.properties蒙山中間體

android.library.reference.1=../../build/intermediates/exploded-aar/com.android.support/appcompat-v7/21.0.3 

更改程序兼容性的版本。

如果你沒有使用指南讀它,它可以有很大的幫助,或閱讀最新的指南http://nenick-android.blogspot.de/2015/03/android-studio-110-and-robolectric-30.html

+1

裏邊反示例代碼是更多的最新https://github.com/nenick/AndroidStudioAndRobolectric – nenick

+0

爲什麼我們需要添加.properties文件? –