public final class DexOpener
extends java.lang.Object
// Specify your root package as `package` statement.
// The final classes you can mock are only in the package and its subpackages.
package your.root.pkg;
public class YourAndroidJUnitRunner extends AndroidJUnitRunner {
@Override
public Application newApplication(ClassLoader cl, String className, Context context)
throws ClassNotFoundException, IllegalAccessException, InstantiationException {
DexOpener.install(this); // Call me first!
return super.newApplication(cl, className, context);
}
}
Then specify your AndroidJUnitRunner as the default test instrumentation runner in your app's build.gradle.
android {
defaultConfig {
minSdkVersion 16 // 16 or higher
testInstrumentationRunner 'your.root.pkg.YourAndroidJUnitRunner'
}
}
| Modifier and Type | Method and Description |
|---|---|
static void |
install(android.app.Instrumentation instrumentation)
Provides the ability to mock your final classes.
|
public static void install(@NonNull
android.app.Instrumentation instrumentation)
instrumentation - the Instrumentation instance of your AndroidJUnitRunner
subclassjava.lang.IllegalStateException - if this method is called twice or is called in an
inappropriate locationjava.lang.UnsupportedOperationException - if the given Instrumentation instance belongs
to a special package such as 'android'newApplication(ClassLoader, String, Context) method overridden in your AndroidJUnitRunner
subclass.