Actions
Unit Testing¶
NFD requires unit testing for most modules.
NFD uses the Boost Unit Test Framework.
Learning Resources for Boost Unit Test Framework¶
- Boost Unit Test Framework documentation
- 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 the--helpcommand line option to get more information about the available options.
Testing Code Guidelines¶
- The test suite for
.../folder/module-name.hppshould be placed intests/.../folder/module-name.t.cpp.- For example, test suite for
daemon/fw/forwarder.hppshould be place intests/daemon/fw/forwarder.t.cpp.
- For example, test suite for
- The test suite should be named
TestModuleName, and nested under test suites named after directories.- For example, test suite for
security/transform/base64-decode.hppis namedSecurity/Transform/TestBase64Decode.
- For example, test suite for
- The test suite should be declared inside the same namespace of the tested type plus additional
testsnamespace.- For example, test suite for
nfd::Forwarderis declared innfd::tests, test suite fornfd::cs::Csis declared innfd::cs. - If needed, parent
testssub-namespace can be imported withusing namespacedirective.
- For example, test suite for
- All test suites for the
nfdbinary itself (i.e., for translation units located underdaemon/subdir) should use theGlobalIoFixturefixture, to get automatic setup and teardown of the globalio_serviceinstance. Other test suites (e.g., for translation units undertools/subdir) must not useGlobalIoFixture.- Similarly, if a custom fixture is needed for a test suite or test case in
daemon/, that fixture should derive, directly or indirectly, fromGlobalIoFixture. KeyChainFixtureshould be used if a test case needs to create identities in KeyChain.ClockFixtureorGlobalIoTimeFixturecan be used if mocked clocks are desired.
- Similarly, if a custom fixture is needed for a test suite or test case in
Testing Helpers¶
tests/daemon/limited-io.hppprovides operation count and time limittests/daemon/face/dummy-face.hppprovides aFacethat doesn't depend on a sockettests/daemon/fw/strategy-tester.hppprovides a facade to test a forwarding strategytests/daemon/fw/topology-tester.hppprovides facilities to test forwarder and strategy in a virtual topology
Updated by Davide Pesavento over 5 years ago ยท 12 revisions