【发布时间】:2016-03-23 13:38:10
【问题描述】:
我在我的 Android 应用中使用 Otto 的 EventBus。
在我的LoginNetworkOperation 类中,我捕获了不同类型的网络连接错误,并为每个错误发布了不同的总线事件,并且我的LoginPresenter 类被注册为侦听器并在触发这些事件时调用某些方法.
我的问题是如何(并且应该)对LoginNetworkOperation 是否引发此事件进行单元测试,而LoginPresenter 是否使用Mockito 处理它?
我查看了这个问题:Guava EventBus unit tests,但它没有提供足够的信息,尤其是在实现部分。
public class LoginNetworkOperation {
public void execute(String username, String password) {
try {
// retrofit attempt
} catch (Exception e) {
bus.post(new ExceptionEvent(e));
}
}
}
public class LoginPresenter {
void onExceptionEvent(ExceptionEvent exceptionEvent) {
// Do Something with the exception event
}
}
另外,这里应该是Subject Under Test,哪个应该是模拟对象?
我在 Android Studio 中使用 JUnit + Mockito + Robolectric,我的测试工件是单元测试
【问题讨论】:
标签: android unit-testing mockito