I need some advices and guidance related to TDD of android applications
I’m developing a complex android application (an automated robo player for a web game). Now i have a pilot for it, and before start continue with it’s development, i want to make full TDD for it.
The main purpose of this application is run as a background service that communicates with a http server – it will send http requests with json content
It has to 2 modes of running:
- service mode - it will run in background- read some data configuration from database and communicate with the server
- GUI mode - communication with server on demand + configuration for running in service mode.
GUI layer is designed as MVP, so all business done in a module (a MVP unit) is separated from view, therefore, all app logic is “NON android dependent”.
I have several big layers that i need to make unit tests for:
- domain data access :
database storage (ormlite)
android specific storage - shared prefs..,
files
- server communication - http client (spring android rest template)
http content conversion (gson)
- background services - android services
- GUI - activities
- app business - android independent - algorithms, computations, ...
In conclusion will need TDD – for every of these layers individually, but also integration tests for a complete flow.
tests included :
- database DAO tests
- http client requests
- GSON conversion TDDs
- business logic - simple tests for methods
- unit testsfor running and scheduled background services
- activity unit testing
- test suites (service + DAO + json conversion + http requests)
My first question is what TDD frameworks would be best for my needs? Should i use mocking or not ?
Please give me some directions to go for. Thanks
At first, for automatic testing : junit.
For fluent assertions, you could look at fest-assertions. They provides a lot of examples, here. But enjoy this one on the
String:It isn’t just harmonious, it increase also your productivity.
Since you want to write unit tests, you will have to write
mockobjects. Of course, you can do it without any framework, but it is verytedious.Personnaly, i am big fan of Mockito. It’s api is great and very fluent. Besides, you could the use the BDDMockito static methods to write test in a BDD manner. Look :
Sometimes you will depend on class that you can’t mock, for example a
final classlikeBluetoothAdapter. In these cases (and only in these), you could usePowerMock.Look also at this stuff :
http://daverog.wordpress.com/2009/12/14/why-android-isnt-ready-for-tdd-and-how-i-tried-anyway/)
There is also a book : Android Application Testing Guide