AS 4.0.2
RxBindings 4.0.0
I have written a unit test for testing if the PublishRelay accept has been called that uses jakeWartons rxBindings
This is the snippet of code I am testing
private val checkStoresRelay: Relay<Unit> = PublishRelay.create<Unit>()
private fun onCheckStockTapped(view: View) {
view.textViewCheckStock
.clicks()
.debounce(TIME_OUT, TimeUnit.MILLISECONDS)
.subscribeBy(
onNext = checkStoresRelay::accept,
onError = { Timber.e(it, it.localizedMessage) }
)
}
In the test class I am doing the following. The textViewCheckStock.performClick()
will trigger and I check that the checkStoresRelay.accept(Unit) had been called.
But I am not sure about the availableDeliveryOptionsModel.checkStoresRelay.accept(Unit)
As I don't think I should be calling this in the test. However, the test will fail if I remove this. Just wondering what would be the best way to test this?
@Test
fun `should check stores when checkStock is tapped`() {
// Arrange
val viewHolder = createViewHolder()
availableDeliveryOptionsModel.bind(viewHolder)
val actual = availableDeliveryOptionsModel.checkStoresRelay.test()
// Act
availableDeliveryOptionsModel.checkStoresRelay.accept(Unit)
viewHolder.itemView.textViewCheckStock.performClick()
// Assert
actual.assertValue(Unit)
}
Many thanks for any suggestions,
from Unit testing to check that the accept was called when using RxBindings
No comments:
Post a Comment