liveBook · Manning

System under test

As explained in The Art of Unit Testing 3e

A system under test is the subject, system, suite, component, class, or code being tested.

A system under test (SUT) is simply the thing a test is checking. It may also be called the subject under test or suite under test; CUT can mean component, class, or code under test. Giving it a name helps separate the production behavior being checked from the test code that triggers and evaluates it. section 1.2

The SUT is not necessarily one function. In unit testing, it can be a unit of work: everything that happens after an entry point is invoked until a noticeable result appears at one or more exit points. A public function may be the entry point, while its work can involve other functions, modules, or components. section 1.2

Calling the SUT directly

A small test can invoke a production function such as sum('1,2'), inspect its returned value, and report a failure when the result is not 3. Here, sum is the SUT; the comparison, error reporting, and exception handling belong to the test harness. Frameworks usually provide those supporting jobs automatically. section 1.6

Listing 1.4 A very naive test against sum()
const parserTest = () => {
  try {
    const result = sum('1,2');
    if (result === 3) {
      console.log('parserTest example 1 PASSED');
    } else {
      throw new Error(`parserTest: expected 3 but was ${result}`);
    }
  } catch (e) {
    console.error(e.stack);
  }
};

Inspect a minimal plain-JavaScript test that calls sum, compares the result, and reports a failed expectation. section 1.6

A clear test name identifies the unit under test, the scenario supplied to it, and the expected result. This USE pattern—unit under test, scenario, expectation—makes failures easier to interpret when a build shows only the test name rather than comments or full test code. section 2.5.3

Name the behavior under test

`verifyPassword, given a failing rule, returns errors` names the SUT (`verifyPassword`), the scenario (a failing rule), and the expectation (errors are returned). That name points toward the likely production-code problem before opening the test body. section 2.5.3

Listing 2.5 Naming a test with USE
test('verifyPassword, given a failing rule, returns errors', () => {
  const fakeRule = input => ({ passed: false, reason: 'fake reason' });
 
  const errors = verifyPassword('any value', [fakeRule]);
  expect(errors[0]).toContain('fake reason');
});

Inspect a USE-style test name alongside its failing-rule scenario and returned-error expectation. section 2.5.3

How The Art of Unit Testing 3e covers it

How deep it goes
Defines the SUT and relates it to entry points, exit points, and units of work without detailing framework internals.
Examples
Uses `sum('1,2')` and `verifyPassword` with a failing rule as test targets.
What it assumes
Introduces SUT terminology from a basic unit-testing context and uses plain JavaScript test examples.
What you can do after
Evaluate/understand which production behavior a test targets and name that behavior, scenario, and expected result clearly.
How it connects
Connects the SUT to unit testing, units of work, entry points, exit points, and USE test naming.

Also explained in

Compare how 4 books explain system under test →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Art of Unit Testing 3e. The section links point to the parts of the book it draws on.