File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Android and the fly likes UNit Testing and TDD for Android Developent Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Android
Bookmark "UNit Testing and TDD for Android Developent" Watch "UNit Testing and TDD for Android Developent" New topic

UNit Testing and TDD for Android Developent

Sahil Reddy
Ranch Hand

Joined: Jan 24, 2011
Posts: 145
Hello Pals,

I want to Unit test while developing for Android. Is there any Good Book or Resource to get started ???

Peter Johnson

Joined: May 14, 2008
Posts: 5852

This prior discussion might help:

JBoss In Action
Richard O'Shay

Joined: Oct 11, 2008
Posts: 9
Unit testing is straightforward despite the mountain of information on it. There is a lot of incorrect information on unit testing, too, such as a method being a unit. Have you ever come across a method outside of a class in Java? In Java the Unit is the class, so a formal unit test must mock out each external dependency (your other classes). If you were to unit test methods you would have to mock all the other class methods! That would be costly and misguided. I suggest Mockito for mocking and TestNG for running your tests. You mock external classes, you test all the public methods of the class-under-test. If there are protected/private methods that are not exercised by that, what are they doing there?

Now, lets back up a bit. You must also perform integration tests to ensure your classes work together. A good boundary for this is the tiers of your application. At a minimum, you should not be making network or database calls as part of your integration tests. Nobody will lose any sleep if you loosely refer to these as "unit tests" but in fact they are integration tests. I would start with these "integration" tests if you are not used to TDD in general, then ease in to true unit tests. You will find it becomes easy, natural, and profitable to implement true unit tests. It can be a hard sell, especially to those who haven't actually done it, or don't really understand it.

We don't know if the climate change whosey-whatsit is man made or just a part of the end of days.
Peter Johnson

Joined: May 14, 2008
Posts: 5852

And another prior discussion:
I agree. Here's the link:
subject: UNit Testing and TDD for Android Developent
It's not a secret anymore!