Зміст курсу
Introduction to QA Automation Testing
Introduction to QA Automation Testing
The `describe` Block
Summary
Sometimes, we might have many tests in a single Test Script, which can become unorganized and hard to manage. For an example, lets create a new file called math.js
with a Math class in it:
This class contains four methods and we write multiple test cases for each method. Since the test cases are related to a single class, therefore, conventionally we would store all the test cases related to it in a single file called math.test.js
:
However, as you might notice, this can become confusing and unorganized since it contains test cases for multiple different methods. If we run the above tests using the verbose
flag, you will see that the tests are all piled up in a sequence with no distinction.
In such situations it is imperative to group together the related test cases using describe
blocks:
Using the above syntax, we can group together the test cases of each method:
Now the code looks more organized, and if we run the tests with the verbose
flag, you will notice that the output is more hierarchical as well, making it easier to see the different test cases for each method.
It is also important to note that we can nest describe blocks to further organize the hierarchy of Test Cases:
The describe
blocks also help in defining the scope of each Test Case. We will see some uses of the scopes of test cases in later topics.
Apart from that, since we typically group together test cases in a describe block, each describe block is referred to as a Test Suite in this case. It is important to note that, in other programming languages, a whole Test Script is typically referred to as a Test Suite.
Дякуємо за ваш відгук!