Skip to content
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

Merged
merged 4 commits into from
May 23, 2016

Conversation

akarnokd
Copy link
Member

@akarnokd akarnokd commented May 12, 2016

This PR adds extra information to assertion failure messages on TestSubscriber and TestObserver, indicating:

  • the listener didn't receive any onCompleted calls, which is an indication of hung or skipping operation,
  • there were errors received, indicating a failure in the event generation process.

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 the assertNoErrors() 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, the AssertionError will have its cause initialized to the actual or composited exception. The message format thus changes:

original assertion message with details (0 completions) (+1 error)
...
caused by
...

This extra information saved me a lot of time in 2.x and Rsc development.

Note that this change doesn't make the assertXXXs 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.

* @param message the message to use for the error
*/
final void assertionError(String message) {
StringBuilder b = new StringBuilder();
Copy link
Contributor

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

Copy link
Member Author

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?

Copy link
Contributor

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#perfmatters

@artem-zinnatullin
Copy link
Contributor

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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TestObserver needs tests too

Copy link
Member Author

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()

Copy link
Contributor

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)",
Copy link
Contributor

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay.

@akarnokd
Copy link
Member Author

Added newline and plural/singular form.

@zsxwing
Copy link
Member

zsxwing commented May 23, 2016

👍 this is really awesome.

@zsxwing zsxwing merged commit 7fed2ed into ReactiveX:1.x May 23, 2016
@akarnokd akarnokd deleted the TestSubscriberMoreDetails branch June 28, 2016 09:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants