UnitTesting » History » Version 5
Junxiao Shi, 02/15/2015 06:57 PM
1 | 1 | Junxiao Shi | # Unit Testing |
---|---|---|---|
2 | |||
3 | NFD requires unit testing for most modules. |
||
4 | |||
5 | 2 | Junxiao Shi | NFD uses [Boost Unit Test Framework](http://www.boost.org/doc/libs/1_48_0/libs/test/doc/html/index.html). |
6 | 1 | Junxiao Shi | |
7 | ## Learning Resources for Boost Unit Test Framework |
||
8 | |||
9 | 2 | Junxiao Shi | * [Boost Unit Test Framework documentation](http://www.boost.org/doc/libs/1_48_0/libs/test/doc/html/index.html) |
10 | 5 | Junxiao Shi | * After compiling the unit-test binary, it is possible at run time to select which tests to run and what kind of output is desired. |
11 | 1 | Junxiao Shi | Use `--help` command line option to get more information about the available options. |
12 | 2 | Junxiao Shi | |
13 | ## Testing Code Guidelines |
||
14 | 1 | Junxiao Shi | |
15 | 5 | Junxiao Shi | * Test suite for `.../folder/module-name.hpp` should be placed in `tests/.../folder/module-name.t.cpp`. |
16 | * For example, test suite for `daemon/fw/forwarder.hpp` should be place in `tests/daemon/fw/forwarder.t.cpp`. |
||
17 | * Test suite should be named `FolderModuleName`. |
||
18 | * Exception: test suite for a header in top-level folder is named `TestModuleName` so that unqualified `ModuleName` still refers to the tested type. |
||
19 | * For example, test suite for `daemon/fw/forwarder.hpp` is named `FwForwarder`, test suite for `src/name.hpp` is named `TestName`. |
||
20 | * Test suite should be declared inside the same namespace of the tested type plus additional `tests` namespace. |
||
21 | * For example, test suite for `nfd::Forwarder` is declared in `nfd::tests`, test suite for `nfd::cs::Cs` is declared in `nfd::cs`. |
||
22 | * If needed, parent `tests` sub-namespace can be imported with `using namespace` directive. |
||
23 | * Test suite should use `nfd::tests::BaseFixture` fixture, to get automatic setup and teardown of global `io_service`. |
||
24 | * If a custom fixture is defined for test suite or test case, that custom fixture should derive from `BaseFixture`. |
||
25 | * `IdentityManagementFixture` should be used if a test case needs to create identities in KeyChain. |
||
26 | * `UnitTestTimeFixture` should be used if mocked clocks are feasible/desirable. |
||
27 | 3 | Junxiao Shi | |
28 | ## Testing Helpers |
||
29 | 1 | Junxiao Shi | |
30 | 3 | Junxiao Shi | * `tests/core/limited-io.hpp` provides operation count and time limit |
31 | * `tests/daemon/face/dummy-face.hpp` provides a `Face` that doesn't depend on a socket |
||
32 | 4 | Junxiao Shi | * `tests/daemon/fw/strategy-tester.hpp` provides a facade to test a forwarding strategy |
33 | 5 | Junxiao Shi | * `tests/daemon/fw/topology-tester.hpp` provides facilities to test forwarder and strategy in a virtual topology |