-
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: support Observable.test() #4777
Conversation
Current coverage is 84.08% (diff: 100%)@@ 1.x #4777 diff @@
==========================================
Files 286 287 +1
Lines 17754 17828 +74
Methods 0 0
Messages 0 0
Branches 2702 2702
==========================================
+ Hits 14943 14990 +47
- Misses 1952 1967 +15
- Partials 859 871 +12
|
I have mixed feelings about this. 2.x required massive amount of unit tests, often with the same structure across the base types where this was a valuable addition. Maybe you could flesh it out in rxjava-extras and provide a function for the import static TestConsumer.*;
Observable.just(1)
.to(newTest(0L))
.assertEmpty()
.requestMore(1)
.assertResult(1); You can base it on |
Just for reference. There are at least two libraries that aim to provide similar functionality (chaining assertions):
|
@akarnokd, @MyDogTom For anyone writing tests for their observables I think this is very attractive functionality to have natively and I was stoked to use it with rxjava 2. Note that my motivation for this is for writing tests in my projects (not rxjava 1.x core, though that would be nice too). I forgot to consider |
How about having an interface with the get and assert methods and the 3 test()s return it. In an internal package then you can implement them and have delegates as necessary. |
Yep I can do that. |
Having extracted an interface the one implementation can serve all |
@@ -16,19 +16,48 @@ | |||
|
|||
package rx; | |||
|
|||
import java.util.*; | |||
import java.util.concurrent.*; | |||
import java.util.Arrays; |
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.
Please make sure you don't unroll *
imports.
ts.assertValue(value); | ||
return this; | ||
} | ||
public interface TestSubscriber2<T> extends Observer<T> { |
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.
I'd call this TestConsumer
because that 2
at the end will make people wonder and question endlessly.
|
||
} | ||
boolean isUnsubscribed(); |
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.
Reinforce with implements Subscription
?
I think |
Unnecessary. TestConsumer should have awaitTerminalEvent that blocks. |
TestConsumer maybe not ideal because sounds like it's a significantly different beast from a TestSubscriber. I prefer to retain the word Subscriber in the name, what about TestSubscriberFluent? |
|
+1 for @akarnokd I still think that |
e47b1ef
to
a789ebd
Compare
@MyDogTom puts it well I think, after all |
fixed imports, renamed squashed commits and rebased on latest 1.x |
If this comes up we will answer that it is the base API interface for asserting a subscriber's state for all 3 reactive types. I see confusion going the other way around: why |
00c2467
to
9bed046
Compare
Righto, let's go with |
* @since 1.2.3 | ||
*/ | ||
@Experimental | ||
public final AssertableSubscriber<Void> test(long initialRequestAmount) { |
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.
Completable
doesn't need backpressure so this method has no use.
* @since 1.2.3 | ||
*/ | ||
@Experimental | ||
public final AssertableSubscriber<T> test(long initialRequestAmount) { |
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.
Single doesn't support backpressure either.
9bed046
to
19bbbfa
Compare
…er and support Observable.test()
19bbbfa
to
ef91729
Compare
Thanks @akarnokd, made fixes and squashed commits. |
The new method chaining
TestSubscriber
in 2.x is too good not to have in 1.x as well (while I wait for 2.x to mature and to make my existing unit tests less verbose).Observable.test()
returns aTestSubscriber2
that wraps aTestSubscriber
and enables method chaining where it can.I've added tests to get to 100% test coverage though I've been pretty slap-dash about testing some of the details (for example I haven't tested that
awaitXXX
really does wait for stuff).I've noted it as
@since 1.2.3
but can update to 1.2.2 if you are happy to squeak it into the release.