由于AutofillManager,Roboelectric无法运行测试

时间:2018-03-16 16:49:31

标签: android unit-testing robolectric android-autofill-manager

我无法让Roboelectric运行我的测试,因为它无法为AutofillManager类创建阴影对象。

@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);
    }

}

我尝试使用模拟对象并使用RobolectricTestRunner运行。测试成功运行。但是看起来像创建的阴影对象无法访问AutofillManager。任何线索?

1 个答案:

答案 0 :(得分:0)

根据对Robolectric问题的评论,compileSdkVersion必须至少为27(https://github.com/robolectric/robolectric/issues/3828#issuecomment-377586971)。那对我有用。