Reputation: 10679
What is the correct flow for testing an Android library? My library heavily relies on android.location
and the Google Play Services fused location provider, so I'd like to be able to test location changes.
After adding the instrumentTest
folder under src
, what should I do? The Gradle User Guide simply says to test the library like a regular app, but since I have no Activity
how do I instantiate my library classes?
Upvotes: 1
Views: 254
Reputation: 690
You should use the InstrumentationTestCase
(and subclasses, depending on your needs).
You can get the Context
by calling getInstrumentation().getContext()
inside your test cases.
When using Gradle you just need to place your test classes in /src/instrumentTest
, and run them by creating an Android test Run Configuration. You can also run the tests from the command line: ./gradlew check
(or, one of the variants, such as connectedCheck
or connectedInstrumentTest
).
Lastly, you should probably mock out all your external dependencies. You might want to look at some mocking framework such as Mockito, or just do stuff yourself.
Upvotes: 2
Reputation: 2291
Why don't you just create a simple app that uses your library? You can use Genymotion to test different locations (including altitude): http://www.genymotion.com/
Upvotes: 1