[go: up one dir, main page]

Discussion: Unit testing style, black box vs white box

Currently, it is the Gitaly style to use internal tests, other wise known as white-box testing. This style of testing makes it possible to interact with unexported symbols in a package under test since it is actually part of the unit under test. This contrasts with black-box testing using a separate package. In Go, there is a special convention for test packages known as the _test package. This package is compiled separately and must import the package under test just as any other package would.

Quick summary of pros and cons:

  • White-box - able to interact with unexported symbols
    • Pros
      • easier to verify internal state
    • Cons
      • internals can potentially be altered and lead to inaccurate testing
      • false sense of test coverage
  • Black-box - only interacts with exported symbols
    • Pros
      • tests the package under test the same way it will be used
    • Cons
      • harder to test; often requires designing an API that is more "testable"

See related discussion: !1268 (comment 175796308)