我无法让 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。有什么线索吗?