Project

General

Profile

UnitTesting » History » Revision 10

Revision 9 (Davide Pesavento, 03/25/2019 08:50 PM) → Revision 10/12 (Davide Pesavento, 03/25/2019 09:05 PM)

# Unit Testing 

 NFD requires unit testing for most modules. 

 NFD uses [Boost Unit Test Framework](https://www.boost.org/doc/libs/1_58_0/libs/test/doc/html/index.html). 

 ## Learning Resources for Boost Unit Test Framework 

 * [Boost Unit Test Framework documentation](https://www.boost.org/doc/libs/1_58_0/libs/test/doc/html/index.html) 
 * After compiling the test binary (or binaries), it is possible at run time to select which tests to run and what kind of output is desired.   
   Use `--help` command line option to get more information about the available options. 

 ## Testing Code Guidelines 

 * The test suite for `.../folder/module-name.hpp` should be placed in `tests/.../folder/module-name.t.cpp`. 
     * For example, test suite for `daemon/fw/forwarder.hpp` should be place in `tests/daemon/fw/forwarder.t.cpp`. 
 * The test suite should be named `TestModuleName`, and nested under test suites named after directories. 
     * For example, test suite for `security/transform/base64-decode.hpp` is named `Security/Transform/TestBase64Decode`. 
 * The test suite should be declared inside the same namespace of the tested type plus additional `tests` namespace. 
     * For example, test suite for `nfd::Forwarder` is declared in `nfd::tests`, test suite for `nfd::cs::Cs` is declared in `nfd::cs`. 
     * If needed, parent `tests` sub-namespace can be imported with `using namespace` directive. 
 * All The test suites for the `nfd` binary itself (i.e., for translation units located under `daemon/` subdir) suite should use the `GlobalIoFixture` `nfd::tests::BaseFixture` fixture, to get automatic setup and teardown of the global `io_service` instance. Other test suites (e.g., for translation units under `tools/` subdir) must not use `GlobalIoFixture`. `io_service`. 
     * Similarly, if If a custom fixture is needed defined for a test suite or test case in `daemon/`, case, that custom fixture should derive, directly or indirectly, derive from `GlobalIoFixture`. `BaseFixture`. 
     * `KeyChainFixture` `IdentityManagementFixture` should be used if a test case needs to create identities in KeyChain. 
     * `ClockFixture` or `GlobalIoTimeFixture` can `UnitTestTimeFixture` should be used if mocked clocks are desired. feasible/desirable. 

 ## Testing Helpers 

 * `tests/daemon/limited-io.hpp` provides operation count and time limit 
 * `tests/daemon/face/dummy-face.hpp` provides a `Face` that doesn't depend on a socket 
 * `tests/daemon/fw/strategy-tester.hpp` provides a facade to test a forwarding strategy 
 * `tests/daemon/fw/topology-tester.hpp` provides facilities to test forwarder and strategy in a virtual topology