Created
November 14, 2013 08:27
-
-
Save dant3/7463329 to your computer and use it in GitHub Desktop.
AndroidTestRunner that works around the problem with different package name in manifest and R class for Robolectric
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
package com.myapp.whatever; | |
import org.junit.runners.model.InitializationError; | |
import org.robolectric.AndroidManifest; | |
import org.robolectric.RobolectricTestRunner; | |
import org.robolectric.res.FsFile; | |
import com.myapp.R; | |
public class AndroidTestRunner extends RobolectricTestRunner { | |
public AndroidTestRunner(Class<?> testClass) throws InitializationError { | |
super(testClass); | |
} | |
@Override | |
protected AndroidManifest createAppManifest(FsFile manifestFile, FsFile resDir, FsFile assetsDir) { | |
return new CustomPackageManifest(manifestFile, resDir, assetsDir); | |
} | |
private static class CustomPackageManifest extends AndroidManifest { | |
public CustomPackageManifest(FsFile androidManifestFile, FsFile resDirectory, FsFile assetsDirectory) { | |
super(androidManifestFile, resDirectory, assetsDirectory); | |
} | |
@Override | |
public String getRClassName() throws Exception { | |
return getRClass().getName(); | |
} | |
@Override | |
public Class<?> getRClass() { | |
return R.class; | |
} | |
@Override | |
public String getPackageName() { | |
return R.class.getPackage().getName(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment