What Are the Pros and Cons of Creative Naming of Test Variables and Data?
A subtle issue that comes up occasionally when writing tests revolves around the question of naming: is it preferable to use creative names for test data, such as Wayne Enterprises
, or to use dry and boring names like Company 1
?
This of course depends on the developer and on the project, but several interesting points come up when examining this question closely.
Many Toptal developers find that tests are easier to read and understand when they use creative naming schemes. The relationships are more naturally apparent. It also makes working with the specs more interesting and less of a drag. This can bring many indirect benefits to the team, helping keep everyone engaged and having fun.
However, it is easy to get distracted when coming up with creative names, leading to reduced productivity, and even resulting in more confusing specs that try to be too “clever”. To keep distractions in check, some Toptal developers restrict their source of names to a limited group of existing works of fiction - for example, Batman, Futurama, and Star Wars.
Another important consideration is that test data must clearly model the relationships you are trying to test for. With creative test names, it can be easy for the test data to suggest relationships that don’t actually exist in the data. Are Mario
and Luigi
siblings or just two users? Additionally, if it is not very clear that a variable name comes from popular culture, it may confuse another coder who doesn’t know the reference. We can expect most developers to recognize that Chewbacca
is just dummy data, but Luke
might be someone you work with, and Millard Fillmore
might not be a name that your colleague in another country recognizes.
It may seem like a minor issue, but keeping work interesting, fun, and easy is very important. If you know your teammates very well, creative test data can actually help keep things moving. But if you are not that familiar with everyone who may be looking at your tests, keeping names more dry and sanitary may be a safer policy.
Contributors
Carl Dunham
Carl has a lifelong passion for building software, systems, and teams. He caught the bug in college, began working with a startup the summer before graduation, and hasn't stopped since. He loves learning new languages and technologies, and most of all, he like using them to build large, interesting things.
Show MoreDave Aronson
Dave has developed software since 1980 in a wide variety of languages, fields, techniques, and domains. He now mostly does Ruby (on and off Rails) but is also skilled in Python, C, Elixir, and much more. He is a seasoned speaker on software development topics at conferences, user groups, and podcasts. With his gathered knowledge, Dave can mentor your devs and advise on processes and tools.
Show MoreBranislav Hašto
Programming has been Branislav's passion for more than 15 years, and he has been programming professionally for more than 4 years now. He has worked mostly with the Java platform, building software for companies from the finance sector. He believes open and honest communication is the key to building successful software. He loves to write code to help people solve their problems.
Show More