Test-Driven Android Development, Part 2

Image for post
Image for post
Image by dailybackgrounds.com
  1. Designing for Test
  2. Introduction to Unit Testing
  3. Behavior-Driven Development(BDD)
  4. Add-ins & Plug-ins
  5. Testing Beyond the Unit Test

Designing for Test

  • Why do we use DTO?
  • Why do we have different layers of classes?
  • And see how a good Object-Oriented-Design leads to a good Test-Driven-Design and vice-versa.
  1. Data Protection: The ability to protect some components of the object from external entities. This is realized by language keywords to enable a variable to be declared as private or protected to the owning class.
  2. Inheritance: The ability for a class to extend or override functionality of another class. The so called child class has a whole section that is the parent class and then it has it’s own set of functions and data.
  3. Interface: A definition of functions or methods, and their signatures that are available for use to manipulate a given instance of an object. In other word, a contract that indicates what a class will do. One of differences between class and interface is, a class describes the attributes and behaviors of an object, and an interface contains behaviors that a class implements.
  4. Polymorphism: The ability to define different functions or classes as having the same name but taking different data types. In other word, Polymorphism is the ability of an object to take on many forms. The most common use of polymorphism in OOP occurs when a parent class reference is used to refer to a child class object.
  • Avoid very long classes. These classes are hard to test and it’s hard to make that class reusable.
  • It doesn’t have to extends anything.
  • It doesn’t have any dependencies on anything.
  • Data Access Object(DAO): These are specific to entities in the persistence layer.
  • Business Logic(Service layer): Play rules on data which comes form DAO. For example check if albums are more than 5. The nice thing about having these layers separated is we can reuse those DAO concepts across different service layers.
  • UI: On top of service layer, and for example searching albums; It talks to service layers, service layers talk to Data Access Object, and DAO talks to Persistence layer.
  • DTO: It’s the piece that ties everything together. It’s often a return type of fetch method, and a parameter of a insert/update/delete method.
  • When your test checks values of the fake, it was used as a mock.
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
  • We have a big class, while we could use sub classes and a parent. So, when in future a feature wants to be added to our application, we easily add it as a sub class.
Image for post
Image for post
Image for post
Image for post

What’s Next?

On the next article, we’ll go through “Introduction to Unit Testing”.

Senior Android Developer at Radio Systems https://www.linkedin.com/in/drjacky/

Get the Medium app