Article thumbnail

The best practices for naming tests

2m
frontend
testing
quality

Intro

The nomenclature must be consistent and clear throughout the solution, so we must take care of this from the beginning.

Prelude

Imagine a huge project where each developer writes tests descriptions in their own way. It will be complete mess. That's why it's a good idea to adopt some rules and stick to them from the beginning of the project

Some consistent rules

Take a look at the following example:

Loading

We can read the following descriptions as one sentence: Pizza meets standards when size is between 30-40cm or Pizza meets standards when plate size is equal to 30cm (look at nested describe block). Thanks to that we are able to read tests as documentation and immediately understand the testing case.

We used the following rules to build the above cases:

  • Unattributable words like 'should' or 'correct' are not allowed
  • Descriptions must be short
  • Descriptions must use only relevant words that explain the situation
  • First 'describe' block begins with a capital letter
  • Every 'it' block begins with a lowercase letter
  • Nested 'describe' block begins with a lowercase letter
  • There shouldn't be any duplication in test descriptions (use nested 'describe' block as in the example)

Summary

Consistency is very important! If you take care of such things from the beginning you will make your project much easier to understand and more enjoyable to work with.

If you enjoyed it, be sure to visit us on Linkedin where we regularly upload content from programming.

I create content regularly!

I hope you found my post interesting. If so, maybe you'll take a peek at my LinkedIn, where I publish posts daily.

Comments

Add your honest opinion about this article and help us improve the content.

created: 10-04-2023
updated: 10-05-2023