zbsz / robotest

Robolectric integration for ScalaTest
9 stars 2 forks source link

Test fails if an AppCompat theme is used in Activity #4

Closed nightscape closed 9 years ago

nightscape commented 9 years ago

Hi @zbsz,

this is probably not directly related to robotest, but when I try to test an Activity that is styled with an AppCompat theme I get this error

[info] Scenario: Start real activity *** FAILED ***
[info]   java.lang.RuntimeException: Could not find any resource  from reference ResName{org.robotest:style/Theme_AppCompat_NoActionBar} from style StyleData{name='AppTheme', parent='@style/Theme_AppCompat_NoActionBar'} with theme null
[info]   at org.robolectric.shadows.ShadowAssetManager$StyleResolver.getParent(ShadowAssetManager.java:517)
[info]   at org.robolectric.shadows.ShadowAssetManager$StyleResolver.getAttrValue(ShadowAssetManager.java:455)

I've created a reproducible test case here.

This issue seems to be known for Robolectric (here the most current issue for 3.0-SNAPSHOT). It seems that the solution requires using a specialized RobolectricGradleTestRunner, but I'm admittedly not understanding the entire discussion.

I'm thankful for any hints on how to fix this and I'll happily create a PR once I've found a solution :)

Best Martin

zbsz commented 9 years ago

Hi, sorry for delay (I'm on vacations with not much internet connection).

The problem seems to be with RoboSuiteRunner.appResourceLoader, it doesn't resolve resources from aars, we may need to add paths for res folders from aars, android-plugin extracts all aar dependencies in target/aars, so we may just try going through all folders there and add res to resource loader. Will look into this once I'm back.

zbsz commented 9 years ago

Looked a bit into it, don't have a working solution yet, but there is a work-around, the same as described in https://github.com/robolectric/robolectric/issues/1334

create /src/main/project.properties file with path to aars dir:

android.library.reference.1=../../target/aars/com.android.support-appcompat-v7-22.1.1

Will check how exactly this is used in robolectric and try passing this references directly in RobolectricSuite, or we can just generate this file automatically (but this seems ugly).

zbsz commented 9 years ago

RobolectricSuite will automatically include exploded aar directories in robolectric manifest, it assumes that this libraries will be in target/aars, this path is configurable as RobolectricSuite.aarsDir field, should be overriden when using different layout (for example when using different sbt android plugin).