This test project for Applicaster, an automatically refreshing Twitter search with persisted history, provides Tweet results from the 10 most influential people.
In designing the search interface, the best practices from the Android Developers site were followed. The app allows you to configure the frequency for updating search results. After investigating Twitter4j, and interacting with Twitter's Web API directly in HashtagSearch Version 1, I ultimately decided to use Fabric's excellent Twitter Kit.
Twitter's Fabric sample app, demonstrates the simplest way to run Fabric with a custom OkHttp client. By combining several interceptor examples I was able to create an effective caching component for my custom OkHttp client.
You'll need to have an account on Fabric.io and an API key for Twitter. Twitter integration was done with the assistance of the Fabric plugin for Android Studio
With Api keys now available, to build the app, you'll need to create and populate those keys into the app/fabric.properties
file. The Fabric for Android plugin will help with this, and you can also refer to the Fabric for Android sample app.
Sample fabric.properties file:
#These keys are provisioned on the plugin. Copy the keys on the plugin here.
twitterConsumerKey=EDIT_THIS
twitterConsumerSecret=EDIT_THIS
#Contains API Secret used to validate your application. Commit to internal source control; avoid making secret public.
apiKey=EDIT_THIS
apiSecret=EDIT_THIS
This project uses Robolectric for unit tests. Robolectric uses Android SDK version 22 for testing because newer versions throw unrelated OpenGL errors.
To setup Robolectric, you'll need to create a new Android JUnit configuration in Android Studio:
- Set
Test Kind:
toAll in package:
- Set
Package:
tocom.actest.nick.hashtagsearch2
- Set
Search for tests:
toIn single module
- Set
Working directory
to$MODULE_DIR$
.
Espresso instrument tests require that you have either an Android device attached or an emulator running. Once you have that, run a test by command-clicking/right-clicking a specific instrument test and choosing run. The run configuration will automatically be created and the test will be launched.
- Thanks to Annyce Davis' very neat and readable interceptors in samples for her book Adept Android
- Thanks to Mike Nakhimovich's better OkHttp header rewriting
- Fabric's Twitter kit for Android excellent sample app
- Stack Overflow example reading and writing ArrayList to a file