Test Driven Development (TDD) is one of the most important skills for Software Engineer in general and for Android Developer in particular because it has a lot of benefits that allow us to build high quality android apps. Before talking about this software methodology I would like to talk about some of scenarios that drive us to use this approach.Lets discuss the first scenario.Suppose you developed an android app then you submitted to Google Play then people downloaded it and figured out how it was working ,after that you got a lot of bad reviews from users about the app’s performance ,caching ,UI Issues,etc so now you have bad quality problem DO you agree?????
Lets see another scenario,you joined new team and your boss asked you to build new feature unfortunately the code is a legacy code (code without tests) .Now you will be frightened like this guy
and this is logical because you did not write this code and do not have confidence to make any change in the code also you have legacy code so this leads us to the quality problem in your code hence, these problems drives us to use Test Driven Development as our software methodology.
Test Driven Development
TDD is a software development process that relies on the repetition of a very short development cycle: requirements are turned into very specific test cases, then the software is improved to pass the new tests, only. This is opposed to software development that allows software to be added that is not proven to meet requirements.
TDD has cycle of three steps
RED : In this step you think about what is your business requirement and convert it to test cases and make sure you test is compiled and failed.
GREEN :In this step you think about how to make your previous test pass and write the actual implementation for the code ,make sure that you write just the minimal code that makes this test pass.
REFACTOR : In this step you think about how to improve the existing code to make it is more clean and maintainable.
Test Driven Development Benefits
TDD has a lot of benefits like the following:
Enable Iterative development
Live Documentation for code
You feel confident about your code and logic.
Your code is cleaner .
Code quality & maintainability increases .
TDD can lead to more modularized, flexible and extensible code
Regression testing is much more easier as automated test cases find bugs
Test Driven Development for Android Development
Now It is time to speak a little about our scope Android Development.To start develop new feature in your app using TDD , the first thing is to write UI test for your feature using Espresso for example
Image for post
Then you start writing Unit Testing for your feature using Junit and Mockito frameworks for example
If you want to know more about each topics ,I have online course on Udemy and this is UDEMY DISCOUNT FOR SHORT TIME
COURSE CONTENT :
Introduction for Test Driven Development(TDD)
Introduction for Behavior Driven Development(BDD)
Testing Types for Android Development (white and black box testing)
learn Junit by exmaples
learn Mockito by examples
Build Android App Using TDD and MVP
additional material for learning