For the last homework in the course, we were assigned the task as a group to create a lesson plan for the class to do and put it in a POGIL activity. My group sat for a while throwing around ideas before I came across something called testing smells/code smells. Testing smells, also known as code smells, which refer to issues and/or warning signs in an individual’s code that won’t necessarily throw an error or cause the code not to run but likely leads to some bigger issue that would cause fundamental problems in the code.
Code smells come in all shapes and sizes and often seem harmless or meaningless such as reusing variable names, repeating lines of code, hard coding data and more. Testing smells typically refers to code smells that occur specifically in the testing files. These mistakes affect the validity, functionality, and reliability of a test.
Since the whole purpose of testing is to check for problems or potential issues in the code, testing smells is a serious issue that is worth learning about. I watched this video on youtube called, “a few common code smells to be aware of and how to fix them”.
In this video, the individual talks about how testing smells can often point to bigger problems in the code which are important to pay attention to. The first code smell that is mentioned in the video is long functions. The video explains how long functions may seem harmless at first, especially to programmers that are first starting out, but the purpose of a function is to perform one task simply and directly. Long functions often do more than one thing, making them complex and convoluted, therefore more prone to causing bugs in the program. This also makes them more difficult to maintain and to fix.
Another testing smell mentioned is duplicate code. Duplicate code is another testing smell that seems harmless because from a technical standpoint, although a tedious task, does it really matter if you rewrite the same line 30 times? While it is true that if you do this perfectly the functionality of the code shouldn’t be affected, the code will still become messy and unreadable. Additionally, repeating code in this manner increases the likelihood of making a mistake. Turning repeat code into a function or having them inherit from a shared class not only improves cleanliness and readability but prevents simple and clerical errors that would cause frustration at a later point in the coding process.
Overall, Testing smells is something that I believe is an important subject matter worth learning about in order to improve coding ability both on a personal and professional level.
From the blog CS@Worcester – The Struggle of Being a Female Student in CS by Noam Horn and used with permission of the author. All other rights reserved by the author.