liveBook · Manning

Negative testing

As explained in Data-Oriented Programming: Reduce software complexity

A negative test case verifies that software behaves correctly when given invalid input or an input that should cause failure.

Negative testing checks that software behaves correctly when an operation should fail. In mutation tests, do not stop after proving that valid data produces the expected state; deliberately supply invalid or conflicting data and verify the failure behavior. section 6.4 section 6.6

Rejecting a duplicate member

Suppose UserManagement.addMember receives Jessie while Jessie already exists. The operation should throw "Member already exists." The test catches the exception and compares it with the expected exception, rather than comparing a successful output state. section 6.4

How Data-Oriented Programming: Reduce software complexity covers it

How deep it goes
Demonstrates setup, execution, exception capture, and comparison, while deferring broader invalid-input categories.
Examples
Tests adding an already-existing member and expects the exact "Member already exists." exception.
What it assumes
Assumes familiarity with unit tests, mutations, input state, and exception handling.
What you can do after
Diagnose failure handling by verifying that invalid mutation input produces the expected exception.
How it connects
Connects unit testing with mutations, exceptions, expected outputs, and system state.

Also explained in

Compare how 2 books explain negative testing →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Data-Oriented Programming: Reduce software complexity. The section links point to the parts of the book it draws on.