liveBook · Manning

Black-box testing

As explained in Learn Go with Pocket-Sized Projects

Closed-box testing evaluates a software system from outside its implementation, typically through its externally accessible interface.

Black-box testing evaluates behavior through a system’s public interface, without depending on its internal fields, functions, variables, or implementation details. In Go, an external test package such as `pocketlog_test` exercises only exported API, keeping tests aligned with what clients can use. section 4.1.5 section 4.6

Apply the technique by:

  • Create a test file in the same directory with the `foo_test` package rather than the implementation package. section 4.1.5
  • Import the package under test and call only exported constructors, methods, functions, and types. section 4.1.5
  • Assert observable results, output, and public error behavior, then add cases for uncovered use cases. section 4.1.5 section 10.3.1

Testing logger output

An external example test constructs a debug logger, calls `Debugf`, and declares the expected standard output: `Hello, world`. The test initially fails while the logger does nothing, turning the public behavior into an implementation target. section 4.1.5

How Learn Go with Pocket-Sized Projects covers it

How deep it goes
Explains external package layout, visibility boundaries, output assertions, and added cases, but not detailed testing theory.
Examples
Uses a logger output example and habit-creation checks for validation results, generated fields, and invalid-input errors.
What it assumes
Assumes basic Go packages and tests, while teaching external test packages and exported-name access.
What you can do after
Apply it via Go tests to verify exported behavior without coupling assertions to private implementation details.
How it connects
Connects package visibility, public APIs, unit testing, test cases, and typed errors.

Also explained in

Compare how 6 books explain black-box testing →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Go with Pocket-Sized Projects. The section links point to the parts of the book it draws on.