Writing Testable Code
An introduction to testing and how to manually test by breaking a code into smaller components
Being active contributors to the development community, the folks at GeekyAnts are innovators who love to research and experiment to come up with groundbreaking tech solutions. One such event led to the recent tech talk that happened where Saurabh Sahu, the CTO of GeekyAnts who has extensive experience in the field, discussed his experience in a group discussion about writing testable code along with exploring the different types of testing and the suitable circumstances for each use case. This insightful article elaborates on the discussions that transpired during the event through an example project where an app is broken down into small parts with test cases written with the intent of improving the code.
What Is Testing?
In software development, testing is the process of checking an application using testing tools and frameworks to identify and fix errors which results in a well-functioning and robust app. In this discussion, the panelists explore the viability of each type of testing and the limitations that come with it. It is a common understanding that not every app can be tested, especially client projects which have deadlines, due to the time constraints that are attached with the assignment due to which developers have to find creative ways to test the product and ensure a successful app. One popular testing process used is the end-to-end testing method wherein the developers try to replicate real life user scenarios to test the functioning of the application on the whole while unit testing involves dealing with the behavior of individual components. In this article, we are going to deal with the topic of unit testing which includes breaking your app into smaller units and testing, creating buttons and checking if each click is successful.
Why Unit Testing?
This method of testing separate units also serves the purpose of strengthening the intent of including that particular component in the app as it shows a working demonstration of the feature. This was further elaborated with an example where the focus of the testing is on the implementation details because of which the logic of the form does not change when a library is updated because of which the attention needs to be brought back to the implementation details in order to ensure an error free app. This brought in another point of concern where complete testing is not possible due to the different testing levels involved in the process because of which the development team should take maximum care to attain the functionalities affecting the code through attentive measures.
To explore more on how to apply unit testing to a certain use case, an experiment was conducted to simplify the booking of vaccination slots on the COWIN platform. Saurabh had noticed the hassles that were being faced by the people of the country were trying to book a slot to get inoculated but the shortage of vaccinations and the unreliability of the COWIN platform in general has made this a task for the majority. He then came across an appointment availability API on the application which could be leveraged to make this process easier. The next assignment was to build an express Node.js application which could break down a few functions which would then send a notification through mail about the availability of slots in the area based on the data that was input. I.e. pin code and email. The purpose of the app would be to run the predefined functions on loop five times a day where a refreshed search would be generated every minute for the next five days.
This event was one of the initial sessions to be conducted about testing and its intricacies. While this discussion covered the basics of writing testable code, there are more discussions soon to be held which will cover interesting topics like TypeScript vs Testable code.
You can watch the entire discussion here.