我想将robolectric添加到现有的实时android-dagger项目
问题是AndroidManifest中的包名称与R文件物理路径不对齐。
robolectric根据清单" package_name"搜索R文件。属性。
我想在我的robolectric测试中使用@Config
@Config(manifest = " --my---path/AndroidManifest.xml",
sdk = 21,
packageName = "com.google.andorid.apps.ridematch",
application = TestApplication.class)
但显然是" packageName"注释无效。
我想在robolectric开源中调试这个, 但是不确定问题代码在哪里。
这是我第一次参与github开源项目的机会
我的尝试:
尝试1) 我认为这个错误在代码中:
@Test
public void shouldAssignThePackageNameFromTheManifest() throws Exception {
AndroidManifest appManifest = newConfigWith("com.wacka.wa", "");
Application application = defaultTestLifecycle.createApplication(null, appManifest, null);
shadowOf(application).bind(appManifest, null);
assertThat(application.getPackageName()).isEqualTo("com.wacka.wa");
assertThat(application).isExactlyInstanceOf(Application.class);
}
所以我写了这段代码:
@Test
public void shouldAssignThePackageNameFromConfigWhenHaveConfigAndManifest() throws Exception {
AndroidManifest appManifest = newConfigWith("com.wacka.wa", "");
Properties properties = new Properties();
properties.put("packageName", "com.robolectric.MyTestClass");
properties.put("application", "com.robolectric.TestTestApplication");
// properties.put("application", "FakeApp");
Config config = Config.Implementation.fromProperties(properties);
Application application = defaultTestLifecycle.createApplication(null, appManifest, config);
shadowOf(application).bind(appManifest, null);
assertThat(application.getPackageName()).isEqualTo("com.robolectric.MyTestClass");
assertThat(application).isExactlyInstanceOf(TestTestApplication.class);
}
In" bind"我使非null的config-package名称覆盖appManifest包名。
但我无法找到谁调用" defaultTestLifecycle.createApplication"
尝试2) 我开始看这个课程及其测试:
@Override
protected AndroidManifest getAppManifest(Config config) {
I saw this test:
@Ignore
@Config(constants = BuildConfig.class, packageName = "fake.package.name")
public static class PackageNameTest {
@Test
public void withoutAnnotation() throws Exception {
}
}
我添加了我的:
@Ignore
@Config(constants = BuildConfig.class, packageName = "fake.package2.name", manifest = "//java/com/google/android/apps/ridematch/environments/debug:AndroidManifest.xml")
public static class PackageNameConfigAndManifestTest {
@Test
public void withoutAnnotation() throws Exception {
}
}
但是测试通过了,所以bug就不存在了。