C++ Boost


The test module

The test classes can be used to define and run tests, and generate test reports.

synopsis

class test(name, sources, run=False, dependencies=[], features=(), condition=None, expected=1)

A test is an artefact that is typically performed as part of a test suite, with special support to collect and report the test outcome.

__init__(name, sources, run=False, dependencies=[], features=(), condition=None, expected=1)

Create a test.

Arguments:
  • name: the test's name

  • sources: artefact(s) to be tested

  • run: Specify what to do. Possible values:

    • False (default): do nothing (but report whether source was updated successfully)
    • True: Run sources
    • an action: Perform action
  • depends: any prerequisite artefacts that have to be completed

  • features: additional features needed to perform this test

  • condition: either a boolean or a feature condition to indicate if this test is to be performed or skipped.

  • expected: the expected outcome

class report(name, tests, fail_on_failures=False)

A test report runs a set of tests and reports a summary.

__init__(name, tests, fail_on_failures=False)

Construct a report. Arguments are the tests to be performed.

print_summary(targets, sources)

Print a summary of the report.

Examples

from faber.artefacts.binary import binary
from faber.test import test, report, fail

passing = binary('passing', 'passing.cpp')
failing = binary('failing', 'failing.cpp')

test1 = test('test1', passing, run=True)
test2 = test('test2', failing, run=True)
test3 = test('test3', failing, run=True, expected=fail)
test4 = test('test4', failing, condition=False)

r = report('test-report', [test1, test2, test3, test4])

Running faber test-report will perform the tests, print out individual results (e.g., 'PASS', 'FAIL', etc.), then print out a summary, such as:

test summary: 1 pass, 1 failure, 1 expected failure, 1 skipped