uniflow-kt / uniflow-kt

Uniflow 🦄 - Simple Unidirectional Data Flow for Android & Kotlin, using Kotlin coroutines and open to functional programming

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Give unique or settable names to mocked view observers (mock, mockk)

erikhuizinga opened this issue · comments

When debugging test code stack traces it helps if you give custom names to mocks.

Currently (Uniflow 0.9.0 with AndroidX), a stack trace might look like this:

java.lang.AssertionError: Verification failed: calls are not exactly matching verification sequence

Matchers: 
Observer(#1).onChanged(eq(...)))

But since the user does not use Observer instances or the Observer class (not directly, at least), this can be confusing.

In the code below you don't give custom names to the MockK mocks you create.

Suggestion: give custom names to these mocks (e.g. "Uniflow UIState Observer mock" and "Uniflow UIEvent Observer mock"), or make them settable through an optional argument to mockObservers for additional flexibility.

The result would still contain Observers, but would then become something like:

java.lang.AssertionError: Verification failed: calls are not exactly matching verification sequence

Matchers: 
Observer(Uniflow UIState Observer mock#1).onChanged(eq(...)))

Here the responsible code:

val viewStates: Observer<UIState> = mockk(relaxed = true)
val viewEvents: Observer<Event<UIEvent>> = mockk(relaxed = true)

I can make a PR if you want.

is still relevant here @erikhuizinga ?

This is not a big issue, but it would be nice to have.

Ha ok, didn't read. It's on the Mockk side then

It has been added in 06a9e75