Skip to content

Instantly share code, notes, and snippets.

@michaelgwelch
Created July 29, 2021 19:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaelgwelch/bd019c80d710632bcaaffe505dae5490 to your computer and use it in GitHub Desktop.
Save michaelgwelch/bd019c80d710632bcaaffe505dae5490 to your computer and use it in GitHub Desktop.
Multi-file tests for one group

Problem Statement

The number of tests for one group (say objects) gets too large to reasonably manage in one file.

So how to break into multiple files

Solution 1

Just break the tests up into operations (instead of groups). But at the top of each file start with a describe('MyGroup')

This isn't great as the group 'MyGroup' gets mentioned multiple times in test explorer and test output.

Like in this example with Enumerations:

  Enumerations
    ✓ works every time

  Enumerations
    When a client is not authenticated
      GET /enumerations
        ✓ should return 200 (OK) and satisfy Metasys spec
      GET /enumerations/{id}
        ✓ should return 200 (OK) and satisfy Metasys spec
      DELETE /enumerations{id}
        When I attempt to delete a custom enum
          ✓ should return a 401 status code (190ms)

This is likely to just get messy.

Solution 2

Decompose into multiple files with one "orchestration" file. This defines the top level describe and it imports all of the other tests and calls them

function tests() {
describe('Op1', function () {
it('tests op1', function () {});
});
}
module.exports = tests;
function tests() {
describe('Op2', function () {});
}
module.exports = tests;
// This is the orchestrator test file
const op1 = require('./Group1-Op1');
const op2 = require('./Group1.Op2');
describe('Group1', function () {
op1();
op2();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment