Unit Tests and Integration Tests

A unit test checks a focused component's behavior. An integration test exercises a boundary between cooperating components.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
1 min
In this article4 chapters
  1. Pick a small decision
  2. Exercise a real boundary
  3. Put each promise at the boundary it needs
  4. Keep failures diagnostic at both levels

Pick a small decision

A function formatting a quantity can be tested with direct string expectations and values like zero or 1500. A parser connected to the formatter also needs a case checking the unit survives the exchange. Function composition explains the role of the intermediate value.

Exercise a real boundary

Two individually correct components can disagree on text encoding, omitted fields, or date formats. Pass a representative file through both and verify the final effect. Keep focused tests for the underlying domain rules.[1]

Put each promise at the boundary it needs

A numeric parser can be examined alone with an invalid string and a valid zero. An import integration test processes an encoded file, invokes parsing and observes stored records. The second can reveal an encoding or field-mapping error invisible to direct parser calls. See structured file parsing checkpoints.

Unit: parse("0") → number zero
Integration: input file with header and zero → stored record with correct ID and value
A real consumer checks the committed result

Keep failures diagnostic at both levels

Cover many parse cases with fast direct tests. Add boundary-crossing cases for contracts between components, such as empty text being passed to the parser. Include one failing integration case to check what the top-level caller can observe.

References

  1. Python Software Foundation, unittest: Unit Testing Framework ↩