How Writing Test Cases Can Help You Understand the Code Base

Sheetal Jain
3 min readMar 8, 2023

In my previous blog, I discussed My two weeks as a Talazen. Welcome to chapter 2!

How I began contributing to Tala's projects

Before joining Tala, I worked as an intern for two startups, where I had the opportunity to work on large-scale projects. Initially, even though they assigned me small tickets to work on, I felt overwhelmed and lost after seeing a complex code base. I felt like I had a limited understanding of the code structure, and the application’s requirements made it difficult to know where to begin; as a result, it took me a long time to merge my first PR.

The first ticket I was assigned at Tala was for writing unit test cases. Test cases are sets of instructions that verify the application’s behaviour under various scenarios. They assist you in gaining a more practical and hands-on understanding of the code base’s requirements and functionalities. You will gain a better understanding of the application’s architecture and how different components interact with one another by writing test cases.

Clearly, the first task is to gain acceptance of a more reasonable view of the future, one that opens possibilities rather than forecloses them.

How did I write my first test case?

I was asked to first learn a Mockito framework and create a proof of concept. I began learning the framework by watching YouTube tutorials that taught me how to write test cases and why they are important. Starting by writing test cases was an effective way for me to quickly understand the high-level design of the codebase and helped me a lot to understand how the different components are connected with each other in the code, which could have been a daunting task if I had started in another way.

I started with unit tests for a class. It looks for a specific response to a specific set of inputs, which helped me understand the functionality of a specific method in the code. When I started writing my first test case, I looked at the existing test cases, which helped me a lot in learning how to write good test cases. The debugger was also useful in understanding the flow of code. I insert breakpoints into the code and then run test cases in debug mode. This task was completed on time. The following task required me to write integration test cases. Integration test cases primarily focus on data transfer between modules that have already been unit tested, interface between modules, and integrated links.

When you write test cases, you’re forced to think critically about the code’s functionality and requirements. You’ll have to read the code, understand its purpose, and identify the different paths the code can take. This process will give you a deeper understanding of how the application works and the different components that make it up.

With this approach, I am making good progress in my internship. I had already merged four PRs and about to start working on a feature task.

What was your first task in the internship, and how did it help you progress?

--

--