Forked from venator85/LibraryProjectTestRunner.java
Last active
October 15, 2016 12:50
-
-
Save schnatterer/4398df8b957c0d38489e3c626f0ca590 to your computer and use it in GitHub Desktop.
A Robolectric test runner for library projects compatible with Android Gradle plugin 2.2.0-alpha6 and later
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
import org.junit.runners.model.InitializationError; | |
import org.robolectric.RobolectricTestRunner; | |
import org.robolectric.annotation.Config; | |
import org.robolectric.internal.bytecode.InstrumentationConfiguration; | |
import org.robolectric.manifest.AndroidManifest; | |
import org.robolectric.res.FileFsFile; | |
import org.robolectric.res.FsFile; | |
public class LibraryProjectTestRunner extends RobolectricTestRunner { | |
public LibraryProjectTestRunner(Class<?> klass) throws InitializationError { | |
super(klass); | |
} | |
@Override | |
protected AndroidManifest getAppManifest(Config config) { | |
AndroidManifest appManifest = super.getAppManifest(config); | |
FsFile androidManifestFile = appManifest.getAndroidManifestFile(); | |
if (androidManifestFile.exists()) { | |
return appManifest; | |
} else { | |
androidManifestFile = FileFsFile.from(getModuleRootPath(config), appManifest.getAndroidManifestFile().getPath().replace("manifests" + File.separator + "full", "manifests" + File.separator + "aapt")); | |
return new AndroidManifest(androidManifestFile, appManifest.getResDirectory(), appManifest.getAssetsDirectory()); | |
} | |
} | |
private String getModuleRootPath(Config config) { | |
String moduleRoot = config.constants().getResource("").toString().replace("file:", ""); | |
return moduleRoot.substring(0, moduleRoot.indexOf("/build")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment