ReactiveX / RxAndroid

RxJava bindings for Android
Apache License 2.0
19.89k stars 2.94k forks source link

Use RxAndroid as dependency for a Jar, suggestions? #362

Closed danielesegato closed 7 years ago

danielesegato commented 7 years ago

I have a java (jar) library for testing utils, I created a working TestRule (actually a MethodRule) to work with Schedulers RxJavaPlugins and RxAndroidPlugins. Now I wanted to include this class into my utility library but I can't because it depends on RxAndroid which is an Android Library. (RxAndroid2 actually).

Specific error:

Error:Module 'my-module:test-utils:unspecified' depends on one or more Android Libraries but is a jar

I can't declare the RxAndroid2 library as testCompile dependency or it wouldn't be visible when including it.

I understand this is not really a problem with RxAndroid but rather a gradle issue, I was just hoping you have some idea on how to achieve what I need without copying that Rule class everywhere I need it.

Thank you.

dlew commented 7 years ago

RxAndroid depends on Android, so it doesn't make much sense to include it in a pure java library. If the testing util library is for testing Android, then it would make sense that it's not pure java either.

Maybe you actually want two util libraries, one for pure java and the other for Android? Then you could create two different rules, one for RxJava and one for RxAndroid. You would include only what's necessary for each test; the pure java tests will only access RxJava, the Android ones can access RxAndroid.

danielesegato commented 7 years ago

As far as I know unit tests are executed in the JVM and they force you to either mock the Android libraries or use Roboeletric or something like that.

I've a class that is supposed to create Observable (Single to be true) and I want to test the returned observable subscribeOn() with IO scheduler and observeOn() in Android Scheduler. This is an Unit test.

To do so I need to replace both schedulers with a custom scheduler. The library help to achieve this.

For unit test I didn't tough I really needed an Android library and I wasn't sure testCompile dependency would let me include an aar library as dependency.

I guess I can split the two part to keep the android one in an android library but before going that route I wanted to check if there was some way of depending solely on the java part of the RxAndroid library.

Thanks for you answer Daniel

dlew commented 7 years ago

You can execute unit tests on an Android device. See: Building Instrumented Unit Tests.

danielesegato commented 7 years ago

@dlew I know, and that's exactly what I'm trying to avoid here :-)

danielesegato commented 7 years ago

@dlew I want to avoid instrumented unit test because of performance issue, specially in the CI I'm currently using which takes around 20 minutes to run empty instrumented unit test.

Anyway Including a android dependency with testCompile works so I'm just going that route. Thanks for your time, I'm closing this.