????????????????????????????????
?????lovexiaov ???????[ 2016/5/27 10:35:27 ] ??????????????? ???????
???????????????á?
?????????????????? Reddit ?? Robolectric and Dagger 2 ??????????????????????????????????????????????????????
???????????DI????? & ???????
????????????У????????????????????????????????????????????????RestApi??DataManager??????????????????????????????????“???”????User??Message??????????????????????????????????
????????ζ???????????????????????????? DI ????????????????????????????????????????????????????????????·???????????
????· ???????????????????
????· ????????????
????99% ?????????????? DI ????????????Activity??Fragment??View??Service???????????????????????????????? DI ???????????????????? MVP ??????????? Android ??????????????????ù????UI????????????????????????????
????DI ??? & ???????
??????????????????????????????? DI ?????????????????????????????????????????????ɡ????????????????????????DI-friendly????????????? DI ?????????????????
????????????????? DI ????????????????????????? Robolectric??????????????
????DI ??? & ?????UI??????
??????????????????? DI ???????????????????????????????????????????????????????
??????????????instrumentation?????Espresso??Robotium???????? instrumentation ??????????? DI ????????????????
?????????? Dagger 2 ?? Robolectric ???????????????????
????(???????????????)
????????·?????? Roboletric ?????????????????Application?????????????????
??????????? application ???ж??????????DaggerAppComponent???????Builder??????????????????????????????????? application ??
????application ??
public class MyApp extends Application {
@NonNull // Initialized in onCreate.
AppCompontent appComponent;
@Override
public void onCreate() {
appComponent = prepareAppComponent().build();
}
// Here is the trick?? we allow extend application class and modify AppComponent.
@NonNull
protected DaggerAppComponent.Builder prepareAppComponent() {
return new DaggerAppComponent.Builder();
}
}
??????????????? application ??
public class MyIntegrationTestApp extends MyApp {
@Override
@NonNull
protected DaggerAppComponent.Builder prepareAppComponent() {
return super.prepareAppComponent()
.someModule(new SomeModule() {
@Override
public SomeDependency provideSomeDependency(@NonNull SomeArgs someArgs) {
return mock(SomeDependency.class); // You can provide any kind of mock you need.
}
})
}
}
??????

???·???
App??С????H5?????????????????Щ??
2024/9/11 15:34:34?????????????????????????
2024/9/10 11:13:49P-One ???????????????????????????????????????
2024/9/10 10:14:12???????????????????????????
2024/9/9 18:04:26??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44