• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

UNit Testing and TDD for Android Developent

 
Sahil Reddy
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Pals,

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

Regards
 
Peter Johnson
author
Bartender
Posts: 5856
7
Android Eclipse IDE Ubuntu
 
Richard O'Shay
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Peter Johnson
author
Bartender
Posts: 5856
7
Android Eclipse IDE Ubuntu
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic