Class TestingFixture

Class Documentation

class TestingFixture
[source]

Encapsulates an isolated Registry, Output, and Result for running tests inside other tests.

TestingFixture is used to test the mutiny framework itself. It owns a private Registry and StringBufferOutput so that tests run through it do not affect the global Registry or console output.

Public Functions

TestingFixture()
[source]

Construct a fixture with its own Registry, Output, and Result.

virtual ~TestingFixture()
[source]
void flush_output_and_reset_result()
[source]

Flush buffered output and reset the Result counters.

void add_test(Shell *test)

Add test to the private Registry.

Parameters:

testShell to register.

void install_plugin(Plugin *plugin)

Install plugin into the private Registry.

Parameters:

pluginPlugin to install.

void set_test_function(void (*test_function)())

Set the test body to a plain function pointer.

Parameters:

test_function – Function to invoke as the test body.

void set_test_function(ExecFunction *test_function)

Set the test body to an ExecFunction.

Parameters:

test_functionExecFunction whose exec() is the test body.

void set_setup(void (*setup_function)())

Set the setup function run before each test body.

Parameters:

setup_function – Function to invoke as setup.

void set_teardown(void (*teardown_function)())

Set the teardown function run after each test body.

Parameters:

teardown_function – Function to invoke as teardown.

void set_output_verbose()
[source]

Enable verbose output on the private Output.

void run_test_with_method(void (*method)())

Run the single test set by set_test_function() with method as its body.

Parameters:

method – Body to execute inside the test.

void run_all_tests()
[source]

Run all tests registered in the private Registry.

unsigned int get_failure_count()
[source]
Returns:

Number of failures recorded so far.

unsigned int get_check_count()
[source]
Returns:

Number of assertions checked so far.

unsigned int get_skip_count()
[source]
Returns:

Number of ignored tests.

unsigned int get_run_count()
[source]
Returns:

Number of tests that actually ran.

unsigned int get_test_count()
[source]
Returns:

Total number of registered tests.

const String &get_output()
[source]
Returns:

The accumulated output string.

Registry *get_registry()
[source]
Returns:

The private Registry.

bool has_test_failed()
[source]
Returns:

true if the last test run recorded at least one failure.

void assert_print_contains(const String &contains)

Assert that the output buffer contains contains.

Parameters:

contains – Substring expected in the output.

void assert_print_contains_not(const String &contains)

Assert that the output buffer does not contain contains.

Parameters:

contains – Substring that must be absent from the output.

void check_test_fails_with_proper_test_location(const char *text, const char *file, int_least32_t line)

Run a test that is expected to fail and verify the failure message.

Parameters:
  • text – Expected substring of the failure message.

  • file – Expected source file in the failure location.

  • line – Expected line number in the failure location.

Public Static Functions

static void line_executed_after_check()
[source]

Sentinel that must be called to prove execution continued past a check.

Call this immediately after an assertion macro in a test that uses TestingFixture; the fixture verifies it was reached.

Protected Functions

void replace_output(StringBufferOutput *new_output)

Swap in a different output object.

Parameters:

new_output – New output to use; the fixture takes ownership.