-
Notifications
You must be signed in to change notification settings - Fork 7.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
1.x: TestSubscriber extra info on assertion failures #3934
Conversation
* @param message the message to use for the error | ||
*/ | ||
final void assertionError(String message) { | ||
StringBuilder b = new StringBuilder(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: you can set some initial capacity to save allocations
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On an unit test failure report?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh damn lol k u good
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#perfmatters
This is great! |
* TestSubscriber, giving more information when some assertXXX check fails. | ||
* @param message the message to use for the error | ||
*/ | ||
final void assertionError(String message) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TestObserver
needs tests too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assertValues
go to testObserver.assertReceivedOnNext()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure… but it's implementation detail…
} catch (AssertionError expected) { | ||
assertEquals("Number of items does not match. Provided: 2 Actual: 3.\n" + | ||
"Provided values: [1, 2]\n" + | ||
"Actual values: [a, b, c] (0 completions) (+1 errors)", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In case of long Actual values: []
number of completions and errors may not be visible enough for the developer, let's move them on new line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay.
Added newline and plural/singular form. |
👍 this is really awesome. |
This PR adds extra information to assertion failure messages on
TestSubscriber
andTestObserver
, indicating:onCompleted
calls, which is an indication of hung or skipping operation,Previously, if there was something wrong with the sequence, the order and type of assertions were mostly unhelpful: if
assertValues
was first, the lack of values failure could hide a revealing onError call. If theassertNoErrors()
was first, the error is visible but no way of knowing how far the sequence got.Now, it is generally okay to use
assertValues
first, which along the difference, will print the lack of completion and the number of exceptions received, plus, theAssertionError
will have its cause initialized to the actual or composited exception. The message format thus changes:This extra information saved me a lot of time in 2.x and Rsc development.
Note that this change doesn't make the
assertXXX
s also assert for completion or error at all. If the values match, but there is an additional error instead of completion, one has to assert that separately, just like now.