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.
- 1. Basics
10 minutes
Software testing
2 m
Grouping the tests
1 minute
The usage of describe and it
2 m
The best practices for naming tests
2 m
Navigating the different types of software tests
3 m
- 2. Mastering unit testing
38 minutes
Project and tests setup
3 m
Unit tests review
4 m
React component testing
5 m
Snapshot testing in React
4 m
Understanding stubs in testing
3 m
Understanding mocks in testing
5 m
Creating testing fixtures
4 m
Using spies in React and Typescript
3 m
Mocking environment variables
3 m
Using dependency injection pattern to improve fixtures
4 m
- 3. Mastering integration testing
12 minutes
Understanding the integration tests
4 m
Using MSW library to remove implementation details from tests
4 m
Creating fixture for MSW to reduce boilerplate and setup
4 m
- 4. Mastering e2e tests
8 minutes
Comments
Add your honest opinion about this article and help us improve the content.