1
我使用Mockito
和Roboelectric
進行測試。 我面對錯誤與方法通用參數,它需要的測試:Mockito通用參數
通緝但未被調用:splashViewState.startActivity( 類ru.techmas.androidtemplate.activities.MainActivity);
SplashPresenter:
@InjectViewState
public class SplashPresenter extends BasePresenter<SplashView> {
@Inject
SplashPresenter(RestApi restApi, TokenHelper preferenceHelper) {
this.restApi = restApi;
this.tokenHelper = preferenceHelper;
startNext();
}
public final void startNext() {
getViewState().showErrorConnection(false);
if (tokenHelper.isFirstRun()) {
getViewState().startActivity(MainActivity.class);
}
}
}
SplashPresenterTest:
@RunWith(RobolectricTestRunner.class)
public class SplashPresenterTest {
@Mock
SplashView splashView;
@Mock
SplashView$$State splashViewState;
@Mock
RestApi restApi;
@Mock
TokenHelper tokenHelper;
private SplashPresenter splashPresenter;
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
splashPresenter = new SplashPresenter(restApi, tokenHelper);
splashPresenter.attachView(splashView);
splashPresenter.setViewState(splashViewState);
}
@Test
public void startNextTest() {
splashPresenter.startNext();
verify(splashViewState).showErrorConnection(false);
when(tokenHelper.isFirstRun()).thenReturn(true);
verify(splashViewState).startActivity(MainActivity.class);//error here
}
}
可能是什麼問題呢?
謝謝你,它的工作! –
不客氣。很高興它解決了! –