Created
August 28, 2012 20:23
-
-
Save pplante/3503788 to your computer and use it in GitHub Desktop.
Robolectric does not support loading resources from an Android Library project such as ActionBarSherlock of FlyInMenu, so this patch allows you to specify a library project to load resources in tests.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// In ResourceLoader.java I added the following method: | |
// | |
public void loadLibraryProjectResources(File libraryProjectRoot) throws Exception { | |
File systemResourceDir = getSystemResourceDir(getPathToAndroidResources()); | |
File localValueResourceDir = getValueResourceDir(libraryProjectRoot); | |
File systemValueResourceDir = getValueResourceDir(systemResourceDir); | |
loadStringResources(localValueResourceDir, systemValueResourceDir); | |
loadPluralsResources(localValueResourceDir, systemValueResourceDir); | |
loadValueResources(localValueResourceDir, systemValueResourceDir); | |
loadDimenResources(localValueResourceDir, systemValueResourceDir); | |
loadIntegerResource(localValueResourceDir, systemValueResourceDir); | |
loadViewResources(systemResourceDir, libraryProjectRoot); | |
loadMenuResources(libraryProjectRoot); | |
loadDrawableResources(libraryProjectRoot); | |
} | |
// Then you need a custom test runner such as: | |
public class MyTestRunner extends RobolectricTestRunner { | |
public MyTestRunner(Class<?> testClass) throws InitializationError { | |
super(testClass); | |
} | |
@Override public void beforeTest(Method method) { | |
try { | |
Robolectric.getShadowApplication().getResourceLoader().loadLibraryProjectResources(new File("submodules/flyinmenu/library/res")); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Where does the getSystemResourceDir comes from? Could you please provide the complete java file including the imports?