MoonUnit
|
Macros to define unit tests. More...
Macros | |
#define | MU_TEST(suite_name, test_name) |
Defines a unit test. More... | |
#define | MU_LIBRARY_SETUP() |
Define library setup routine. More... | |
#define | MU_LIBRARY_TEARDOWN() |
Define library teardown routine. More... | |
#define | MU_FIXTURE_SETUP(suite_name) |
Define test fixture setup routine. More... | |
#define | MU_FIXTURE_TEARDOWN(suite_name) |
Define test fixture teardown routine. More... | |
#define | MU_LIBRARY_CONSTRUCT() |
Define library construct routine. More... | |
#define | MU_LIBRARY_DESTRUCT() |
Define library destruct routine. More... | |
#define | MU_LIBRARY_INFO(info_key, info_value) |
Define library metadata. More... | |
#define | MU_LIBRARY_NAME(lib_name) |
Define library name. More... | |
This module contains macros to define unit tests as well as library and fixture setup and teardown routines.
#define MU_FIXTURE_SETUP | ( | suite_name | ) |
Defines the setup routine for a test fixture – an environment common to all tests in a particular suite. This routine will be run immediately before each test in the given suite. The setup routine may signal success or failure before the test itself is executed; in this case, the test itself will not be run.
This macro should be followed by the body of the setup routine enclosed in curly braces.
Example:
suite_name | the unquoted name of the test suite for which the setup routine is being defined |
#define MU_FIXTURE_TEARDOWN | ( | suite_name | ) |
Defines the teardown routine for a test fixture – an environment common to all tests in a particular suite. This routine will be run immediately after each test in the given suite. A teardown routine may signal failure, causing the test to be reported as failing even if the test itself did not. This may be used to enforce a common postcondition for a suite of tests, free resources acquired in the setup routine, etc.
This macro should be followed by the body of the setup routine enclosed in curly braces.
Example:
suite_name | the unquoted name of the test suite for which the setup routine is being defined |
#define MU_LIBRARY_CONSTRUCT | ( | ) |
Defines an optional construct routine which will be executed exactly once by the test harness when this library is loaded. It should be followed by a curly brace-enclosed code block. Library constructors are designed to allow initialization of state and resources once as opposed to each time a test within the library is run. This may be useful for certain kinds of external state, e.g. setting up files on the filesystem or starting up a server application which will be used by unit tests.
Example:
#define MU_LIBRARY_DESTRUCT | ( | ) |
Defines an optional destruct routine which will be executed exactly once by the test harness when this library is unloaded. It should be followed by a curly brace-enclosed code block. Library destructors are designed to allow cleanup of state and resources once as opposed to each time a test within the library is run. This may be useful for certain kinds of external state, e.g. deleting temporary files on the filesystem or shutting down a server application which was used by unit tests.
Example:
#define MU_LIBRARY_INFO | ( | info_key, | |
info_value | |||
) |
This macro allows library metadata to be defined in an extensible manner. The only key presently supported is "name", which sets the internal name of the test library – see MU_LIBRARY_NAME() for more information.
In the future, additional keys may be available to take advantage of new features or settings in the test loader.
Only one instance of MU_LIBRARY_INFO() should appear in a library for a given key.
Example:
info_key | the unquoted metadata key to set |
info_value | the quoted value to assign to the key |
#define MU_LIBRARY_NAME | ( | lib_name | ) |
This macro sets the name of the test library to the given string. The library name is used by MU_RESOURCE() during resource lookup, by test loggers during logging, and by the moonunit program itself when specifying the desired subset of tests to run. Extensions or naming conventions of dynamic shared objects may differ between platforms; MU_LIBRARY_NAME() allows you to establish a consistent internal name for your test library.
This setting is optional. If an explicit name is not specified, it will default to the file name of the shared object with the file extension removed.
This macro is equivalent to MU_LIBRARY_INFO(name, lib_name)
Example:
lib_name | the quoted name of this library |
#define MU_LIBRARY_SETUP | ( | ) |
Defines an optional setup routine which will be executed before each test in the library. It should be followed by a curly brace-enclosed code block. Only one instance of this macro should appear in a given library.
Example:
#define MU_LIBRARY_TEARDOWN | ( | ) |
Defines an optional teardown routine which will be executed once after each test in the library. It should be followed by a curly brace-enclosed code block. Only one instance of this macro should appear in a given library.
Example:
#define MU_TEST | ( | suite_name, | |
test_name | |||
) |