TestCafe: How to organize test suites

Ryan Song
3 min readSep 8, 2021

--

Organizing test suites by using TestCafe built-in feature

https://testcafe.io/

Organizing Tests

Usually, in an automation test project, there will be at least one test suite which has one or more test groups. Under each test group, there will be one or more test cases. Features that help organize these test cases are essential for test automation projects. Many junior level automation testers do not have the high level picture of what a project should looks like, which make it difficult for them to organize test cases in code repository.

Fixture vs. Test

TestCafe has built-in features to help organize test cases. You just need to create a .js file, such as testcafe-test-suite.js. Within the testcafe-test-suite.js file, you will add fixtures and tests. A fixture is a test group, and you can have many fixtures within one testcafe-test-suite.js file. Within each fixture, you can have one or more tests, and each test represent a single test case.

Skipping Tests

Sometimes, we want to ignore a specific test case since it is not ready to be re-tested, or we want to run a specific test case after a bug fix. In these scenarios, we will need to tell TestCafe to skip a test case or run only one test. TestCafe has made such tasks easy by having .skip and .only functions. If you want to skip a specific fixture or test, you just need to use fixture.skip or test.skip. Similarly, if you only want to only run a single fixture or a test, you can use fixture.only or test.only.

Fixture and Test Hooks

Another popular way to organize test cases is to execute functions before and after the test cases. TestCafe has built-in hooks to implement this type of task. There are four hooks, beforeEach, before, after and afterEach. In the 1st test case below, beforeEach function will maximize the browser window first, then the before function will resize the browser window to (200, 100). Once the first test case finished running all test steps, the After function will click on the refresh page button. Then the afterEach function will click on the close window button. The same process will repeat for the 2nd test case, the difference is that, this time, the browser window will be resized to (400, 200). Note: If test.before or test.after is specified, it overrides the corresponding fixture.beforeEach and fixture.afterEach hooks, and the latter are not executed. (TestCafe official documentation)

Fixture and Test Metadata

If you want to cherry-pick specific test case for specific type of test runs, such as smoke test or regression test, TestCafe also has built-in feature for you. Fixture and test metadata will let you filter additional information.

--

--

Ryan Song
Ryan Song

No responses yet