Search
⌘K
    to navigateEnterto select Escto close

    Test Suite and Test Case

    Test Suite

    • describe is a Cypress method for grouping one or more related tests.
    • Each describe block represents a test suite. Every time we start writing a new suite of tests for a functionality, we wrap it in a describe block.
    1describe("Test suite", () => {
    2  ...
    3  ...
    4
    5});
    • As we can see describe block takes two arguments: a string for description of the test suite, and a callback function for wrapping the actual test.

    Test Case

    • A test case can be written using it block.
    • A test suite can contain one or more test cases. A test suite can consist positive and negative test cases related to a functionality. This means that describe can have one to more it blocks.
    1describe("Test suite", () => {
    2  it("test case 1", () => {
    3    .....
    4
    5  });
    6
    7  it("test case 2", () => {
    8    .....
    9
    10  });
    11
    12  ...
    13
    14  it("test case n", () => {
    15    .....
    16
    17  });
    18});

    Conventions for describe and it block

    • The description of a describe block must start with uppercase
    • The description of describe block should be short.
    • Avoid using “should” or long statements in describe block.
    • It can simply be the functionality name.

    e.g. If we are testing 'signup' functionality, then the describe block should look like:

    1describe("Signup", () => {
    2  ...
    3  ...
    4
    5});

    e.g. If we are testing 'login' functionality, then the describe block should look like:

    1// Incorrect
    2
    3describe("Verify login functionality", () => {
    4  ...
    5  ...
    6
    7});
    8
    9// Correct
    10
    11describe("Login", () => {
    12  ...
    13  ...
    14
    15});
    • The description of a it block should always be in lowercase.
    • The description of it block can be more specific.
    • We can start the description with should or must. However, it's not mandatory to start with these keywords, just ensure that it is meaningful.

    e.g. If we are handling 'customers' in a test suite, our test should look like:

    1// correct
    2
    3describe("Manage customers", () => {
    4  it("should verify customer operations", () => {
    5    ..
    6    ...
    7
    8    // expected to cover create, edit and delete operations in this test case.
    9
    10  });
    11});
    • Avoid using vague or generic description.
    1//Incorrect
    2
    3it("should verify customer", () => {
    4  ..
    5  ...
    6
    7});
    Previous
    Next