2

I cannot get Roboelectric to run my test because it cannot create a shadow object for AutofillManager class.

@RunWith(RobolectricTestRunner.class)
@org.robolectric.annotation.Config(constants = BuildConfig.class)
public class ConnectivityManagerTest
{
private ConnectivityManager connectivityManager;
private ShadowNetworkInfo shadowOfActiveNetworkInfo;
private ShadowConnectivityManager shadowConnectivityManager;

@Before
public void setUp() throws Exception {
    ConnectivityManager connectivityManager = (ConnectivityManager) ShadowApplication
            .getInstance().getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
    shadowConnectivityManager = shadowOf(connectivityManager);
    shadowOfActiveNetworkInfo = shadowOf(connectivityManager.getActiveNetworkInfo());
}

   @Test
    public void getActiveNetworkInfo_shouldInitializeItself() {
    assertNotNull(shadowOfActiveNetworkInfo);
    }

}

I've tried using mock objects instead and running with RobolectricTestRunner. The test ran successfully. But look's like the shadow objects created cannot access AutofillManager. Any clue ?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Claude Hangui
  • 426
  • 3
  • 8
  • 29
  • Have you found a solution to this issue? – guy.gc Mar 27 '18 at 14:46
  • 1
    Sadly no mate... I did published the issue in github's Roboeletric repository. So far nothing – Claude Hangui Mar 27 '18 at 21:56
  • Thanks for the reply. I'll try to find the github issue and follow it as well. I encountered this issue trying to upgrade from robolectric:3.5.1 to 3.8. For now I'm sticking to 3.5.1 – guy.gc Mar 28 '18 at 06:38

1 Answers1

0

According to the comment on the Robolectric issue the compileSdkVersion needs to be at least 27 (https://github.com/robolectric/robolectric/issues/3828#issuecomment-377586971). That worked for me.

Tigran
  • 3
  • 2