Tests Contain Context

From

editione1.0.1

Updated August 7, 2023

An underrated technique for studying an unfamiliar codebase is to read through the automated tests. While itโ€™s not the most glamorous part of the codebase, thereโ€™s an enormous amount of institutional knowledge stored in the test files. Automated tests are where past and present developers have codified the specifications the application is expected to operate within.

Most young developers donโ€™t realize that a mature test suite will show you exactly how a program should perform, because each test thatโ€™s added to the suite should be designed to validate a specific part of the program for a specific scenario. As you read through the test cases, youโ€™ll see what edge cases the tests handle and what the expected outcomes should be.

Additionally, the assertions in automated tests will show you what the expected output should be when you call a function. Assuming the tests are passing, this gives you a clear picture of how the system works and what application states you should expect.

Donโ€™t Try to Understand It All

Codebases are complex, plain and simple. A codebaseโ€™s complexity can be roughly estimated as proportional to the number of engineers who have contributed to the codebase multiplied by its age. As more developers contribute to a codebase over time, the complexity continues to increase.

Itโ€™s almost impossible to understand every line of a codebase, especially if you didnโ€™t write it yourself. In fact, even a solo developer who has written every single line of a codebase will forget the details and context of parts of the system over time. They may come back to a file they wrote months ago and struggle to remember how it works.

Setting the right expectations now will help reduce your frustrations in the future. Itโ€™s okay if you donโ€™t understand how every line of code in a program works.

Youโ€™re reading a preview of an online book. Buy it now for lifetime access to expert knowledge, including future updates.
If you found this post worthwhile, please share!