One might think “What now?” after delivering a working product to the client for feedback.
Developers deliver a feature by following the user acceptance criteria provided by the client. This includes common functionalities such as field validation, exception handling, and informative user prompts (for information and error). In the effort of making the application as bug-free as possible, we still cannot avoid having issues during our first try. This means we need to carry out new versions of the app that include fixing the problems addressed by the client.
Providing fixes to bugs and issues is not as easy as it seems. Fixing a simple bug might end up affecting working functionalities, or reopening previously closed issues. The last thing we want to happen is our client reporting these kinds of issues. This is where Android Unit Testing comes to play its important role as a software testing method.
Android Unit Testing is where working activities, classes, and functions can be tested across multiple test cases to check the unit’s correctness and integrity. This can be classified as Local Tests and Instrumented Tests.
Local Tests has little to no dependency on Android. It runs on the local development machine without using the emulator. Instrumented Tests, on the other hand, runs on an Android emulator or Android device to check the expected behavior of the app from a set of rules. Such tests can include database procedures, app navigation, and UI Testing.
Local Tests are achieved by using the API provided by JUnit 4 framework, while Instrumented Tests can be achieved straightforward by using Android Studio. A Local Test case can be a set of “asserting” expected results to a returned value from a unit, while Espresso testing framework is the heart of Instrumented Tests. Instrumented Tests require more code to perform UI operations such as button click, input value to input controls, and check control visibility.
Oftentimes, developers ignore Android Unit Testing for some reason. One reason is that it is time-consuming to compose a set of tests that is not part of the scope of the project. Another reason is that developers lack resources and references to perform this method, or they are not accustomed to doing it on previous projects.
Android Unit Testing is an investment in an organization. Investing hours on performing Android Unit Testing will be beneficial in the future. This is also a marketing point for the company to ensure the clients are offered high-quality software through proper development processes.
In my experience as an Android Developer, I started with using Eclipse as Integrated Development Environment (IDE) since it is the only choice available. Eclipse is easy to use especially if you are a Java Developer. In mid-2013, Android Studio was introduced and had a stable build in late 2015. It was a no-brainer for me to shift to Android Studio since it is developed by Google and is dedicated specifically to Android development.
One feature of Android Studio worth using is Lint Code Inspection. By running this code inspector, you will get a list of code construction issues worth fixing. Examples of coding issues are:
- Accessibility (used for persons with disabilities)
- Internationalization (hard-coded texts and bidirectional texts)
- Performance (unused resources, useless parent layout)
- Imports (unused import)
- Probable bugs (constant conditions and exceptions)
- XML (unused XML schema declaration and XML tag empty body)
- Spelling (typographical errors)
- Data flow issues
- Declaration redundancy
- Error handling
These issues are not mandatory fixes, but it can help out improving your code from unnecessary code processing—which may be a potential drawback of the application.
So, the next time you hit a milestone in your project, better consider working to improve your code and perform unit testing. Utilize the tools available for development, and invest in proper software development habits—this will be beneficial to your organization as well as to your professional career.