我正在使用RxJava进行即时搜索,代码如下:
private CompositeDisposable disposable = new CompositeDisposable();
disposable.add(RxTextView.textChangeEvents(searchView)
.skipInitialValue()
.debounce(300, TimeUnit.MILLISECONDS)
.distinctUntilChanged()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribeWith(searchShoppers()));
private DisposableObserver<TextViewTextChangeEvent> searchShoppers()
{
return new DisposableObserver<TextViewTextChangeEvent>()
{
@Override
public void onNext(TextViewTextChangeEvent textViewTextChangeEvent)
{
Log.d(TAG, "Search query : " + textViewTextChangeEvent.text()); shopperAdapterFilterablePort.getFilter().filter(textViewTextChangeEvent.text());
}
}
@Override
public void onError(Throwable e)
{
Log.e(TAG, "onError: " + e.getMessage());
}
@Override
public void onComplete()
{
}
};
}
我正在尝试使用Mockito对这段代码进行单元测试。学习曲线非常陡峭,我只能做到这一点:
public class InstantSearchTest
{
// Step 1
// Test string
// Step 2
// Mock a disposable
// Step 3
// Mock disposable observer
// Step 4
// Step 5
// Step 6
@Test
public void setUpElements()
{
String testString = "test";
TestScheduler testScheduler = new TestScheduler();
}
}
关于如何为此编写好的单元测试的任何建议。