Home

Testing: Separation of concerns

Gunar Gessner

Gunar Gessner

Jun 4, 2021

Tests are usually made of three different concerns:

  1. Setup
  2. Execution
  3. Assertions

When writing tests, you should represent this distiction visually, using empty lines:

test("returns foo", () => {
  // Setup

  // Execution

  // Assertions
})

Here's an example:

describe("verifyKey", () => {
  it("returns true for valid cryptographic keys", () => {
    const { publicKey } = crypto.generateKeyPair();

    const actual = crypto.verifyKey(publicKey);

    const expected = true,
    assert.strictEqual(actual, expected);
  });
});

Sign up for the newsletter


Read other stuff