Skip to content

Instantly share code, notes, and snippets.

@hoombar
Created August 17, 2016 11:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hoombar/201a10a4a82a189dc3a1ef07452c4187 to your computer and use it in GitHub Desktop.
Save hoombar/201a10a4a82a189dc3a1ef07452c4187 to your computer and use it in GitHub Desktop.
public class CustomTestRunner extends RobolectricTestRunner {
/**
* Creates a runner to run {@code testClass}. Looks in your working directory for your AndroidManifest.xml file
* and res directory by default. Use the {@link Config} annotation to configure.
*
* @param testClass the test class to be run
* @throws org.junit.runners.model.InitializationError if junit says so
*/
public CustomTestRunner(Class<?> testClass) throws InitializationError {
super(testClass);
}
@Override
protected AndroidManifest getAppManifest(Config config) {
String path = "src/main/AndroidManifest.xml";
// android studio has a different execution root for tests than pure gradle
// so we avoid here manual effort to get them running inside android studio
if (!new File(path).exists()) {
path = "judo-reference/" + path;
}
config = overwriteConfig(config, "manifest", path);
return super.getAppManifest(config);
}
protected Config.Implementation overwriteConfig(
Config config, String key, String value) {
Properties properties = new Properties();
properties.setProperty(key, value);
return new Config.Implementation(config,
Config.Implementation.fromProperties(properties));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment