- Notifications
You must be signed in to change notification settings - Fork 7.6k
Description
This applies to both 2.x and 3.x, and while I'd like this to be fixed in 2.x, it's more of a frustration than a bug.
Suppose I'm trying to assert that a value from a TestObserver is equal to a particular value. I write this test:
Single.just("foo").test().assertValue("bar")and get this helpful error message:
java.lang.AssertionError: expected: bar (class: String) but was: foo (class: String) (latch = 0, values = 1, errors = 0, completions = 1) Expected :bar (class: String) Actual :foo (class: String) (latch = 0, values = 1, errors = 0, completions = 1) (Never mind that the "Actual" in this case includes extra information, it conveys what it needs to.)
Suppose that I instead use a predicate:
Single.just("foo").test().assertValue { it.equals("goodbye", ignoreCase = true) }Now I get this error message instead:
java.lang.AssertionError: Value not present (latch = 0, values = 1, errors = 0, completions = 1) I'm told that the value isn't present, which is slightly misleading as "not present" is different than "does not match predicate." But more importantly, I don't see what the "not present" value is, which is immensely helpful when debugging the test. My usual solution here is to use something like this instead:
Single.just("foo").test().assertValue { assert(it).isEqualTo("bar", ignoreCase = true) true }This code is more clunky, but gives me the actual value in the error message:
java.lang.AssertionError: Expected :"[bar]" Actual :"[foo]" The cost is that I lose useful (latch = 0, values = 1, errors = 0, completions = 1) information.
Instead of having to make a choice between these two, it would be most helpful if the simplest solution was also just as informative:
java.lang.AssertionError: Value bar (class: String) did not match predicate (latch = 0, values = 1, errors = 0, completions = 1) This extends to many other assertions as well. For example, if I called assertNoValues() but there was a value? I'd like to know what that value was.