【发布时间】:2016-03-17 14:50:34
【问题描述】:
我在我的项目中使用AndroidAnnotations,我想测试一个演示者。
测试套件运行,@Test 方法显然在注入完成之前被调用,因为每当我尝试在我的测试代码中使用 `LoginPresenter 时,我都会得到 NullPointerException。
@RunWith(MockitoJUnitRunner.class)
@EBean
public class LoginPresenterTest {
@Bean
LoginPresenter loginPresenter;
@Mock
private LoginView loginView;
@AfterInject
void initLoginPresenter() {
loginPresenter.setLoginView(loginView);
}
@Test
public void whenUserNameIsEmptyShowErrorOnLoginClicked() throws Exception {
when(loginView.getUserName()).thenReturn("");
when(loginView.getPassword()).thenReturn("asdasd");
loginPresenter.onLoginClicked();
verify(loginView).setEmailFieldErrorMessage();
}
}
【问题讨论】:
标签: android junit mockito android-annotations