I am trying to use ShadowClass Crashlytics / Fabric so that Robotlectric 3 tests do not fail. What I'm still like this:
A custom test runner that adds the Shadow class to Fabric:
public class TestRunner extends RobolectricGradleTestRunner {
public TestRunner(Class<?> klass) throws InitializationError {
super(klass);
}
@Override
protected ShadowMap createShadowMap() {
return super.createShadowMap()
.newBuilder().addShadowClass(ShadowFabric.class).build();
}
@Override
public InstrumentationConfiguration createClassLoaderConfig() {
InstrumentationConfiguration.Builder builder = InstrumentationConfiguration.newBuilder();
builder.addInstrumentedClass(ShadowFabric.class.getName());
return builder.build();
}
}
Shadow grade for fabric:
@Implements(Fabric.class)
public class ShadowFabric {
@Implementation
public static Fabric with(Context context, Kit... kits) {
System.out.println("Shadowing Fabric");
return null;
}
}
My application class for my application:
public class MyApp extends Application {
@Override
public void onCreate() {
setupCrashlytics();
}
protected void setupCrashlytics() {
Crashlytics crashlyticsKit = new Crashlytics.Builder().core(new CrashlyticsCore.Builder().disabled(BuildConfig.DEBUG).build()).build();
Fabric.with(this, crashlyticsKit);
}
}
And here is the test that passes in Debug (since Crashlytics is disabled on it), but does not work in release mode, because ShadowClass does not work correctly:
@RunWith(TestRunner.class)
@Config(constants = BuildConfig.class, sdk=21, packageName="com.my.release.package.name", shadows={ShadowFabric.class})
public class MyTest {
@Test
public void testGreenDAOsave() {
}
}
The error during the Crashlytics / Fabric test is this:
STANDARD_ERROR
io.fabric.sdk.android.services.concurrency.UnmetDependencyException: com.crashlytics.android.core.CrashlyticsMissingDependencyException:
This app relies on Crashlytics. Please sign up for access at https://fabric.io/sign_up
install an Android build tool and ask a team member to invite you to this app organization.
The stack trace shows that MyApp.setupCrashlytics () is being called and Fabric.with () crashes.
1) YES, the application is registered using Crashlytics.
2) YES, I contacted Crashlytics Support Email. I was told: "Robolectric is not supported."
, , , Crashlytics , init'd.
/ !