0

I try to run robolectric + dagger

but I get this error

1) sendWrongPaymentDetails(com.google.android.apps.ridematch.payments.SetPaymentActivityTest)
java.lang.IllegalArgumentException: No inject registered for members/com.google.android.apps.ridematch.payments.SetPaymentActivity. You must explicitly add it to the 'injects' option in one of your modules.
    at dagger.ObjectGraph$DaggerObjectGraph.getInjectableTypeBinding(ObjectGraph.java:361)
    at dagger.ObjectGraph$DaggerObjectGraph.inject(ObjectGraph.java:343)
    at com.google.android.apps.common.inject.ActivityInjectHelper.inject(ActivityInjectHelper.java:70)

I have added this:

    /**
     * Dagger bindings for Ridematch app. Responsible for providing implementations of all injected
     * classes.
     */
    @Module(
      injects = { // Classes that receive injections.
        ApiHelper.class,
        ...
        SetPaymentActivity.class,
        SetPaymentActivityTest.class,

This is my test code:

@Config(
        manifest = "//java/com/google/android/apps/ridematch/AndroidManifest.xml",
        qualifiers = "fr-normal-port-hdpi",
        sdk = 21,
        application = TestApplication.class)


public class SetPaymentActivityTest {

    SetPaymentActivity activity;

    @Before
    public void setUp() throws Exception {
        activity = Robolectric.buildActivity(SetPaymentActivity.class)
                .create()
                .get();
    }

    @Test
    public void sendWrongPaymentDetails() throws Exception {

//        SetPaymentActivity activity = Robolectric.buildActivity(SetPaymentActivity.class)
////                .attach()
//                .create()
////                .starst()
////                .resume()
////                .visible()
//                .get();
         activity = Robolectric.setupActivity(SetPaymentActivity.class);

//        Shadows.shadowOf(SetPaymentActivity.class);

        String url = activity.getUrl();
        assertThat(url, equalTo(""));
    }

how can I fix this?

Elad Benda
  • 35,076
  • 87
  • 265
  • 471

0 Answers0