Skip to content

Unit Tests

Marc Mosko edited this page Feb 2, 2016 · 1 revision

CCNx NS3 Unit Test Conventions

We use the NS3 xUnit-style unit testing framework, but have added a few extra macros and functions to make writing tests easier! We like unit tests, so there are a lot of them.

Location

We use an out-of-source tree directory ccnx/test for all the unit tests. This directory follows the same structure as ccnx/model, so each subdirectory under model has a corresponding subdirectory under test. We aim for every source code module (.cc file except examples) having a corresponding unit test module and for reasonable unit test coverage.

Unit test macros

The header ccnx/test/TestMacros.h defines the BeginTest() and EndTest() macros. These wrap the creation of the derived ns3::TestCase class to reduce the clutter in a test suite with many tests.

For example, to test a class Foo, the test suite would look like this:

 namespace TestSuiteFoo {
   BeginTest(TestGetVersion)
     {
         printf("DoRun Test GetVersion() method\n");
         NS_TEST_EXPECT_MSG_EQ (true, true, "The truth");
     }
   EndTest()
  
   static class TestSuiteFoo : public TestSuite
   {
   public:
     TestSuiteFoo() : TestSuite ("TestSuiteFoo", UNIT)
       {
         AddTestCase (new TestGetVersion (), TestCase::QUICK);
       }
   } g_TestSuiteFoo;
   
 }; // namespace

Conventions

  • A TestSuite is made up of TestCase classes and a TestSuite class that wraps them together.
  • Because all tests are compiled in to the same library, all TestCase and TestSuite must have unique names.
  • In a test module for class CCNxFoo:
    • Use a namespace to wrap all unit tests and the test suite. Name it ns3::ccnx::CCNxFooTests.
    • Use BeginTest() and EndTest() to wrap the TestCase classes. To test a method named Bar, use a name like TestBar or TestBar_ConditionX and TestBar_ConditionY.
    • Use a TestSuite named TestSuiteCCNxFoo and a global variable g_TestSuiteCCNxFoo.
  • Home
  • [Getting Started](Getting Started)
  • Developer
    • [Node Architecture](Node Architecture)
    • [Header doc format](Header doc format)
    • [Unit Tests](Unit Tests)
    • [Overriding Implementations](Overriding Implementations)
    • [Code Coverage](Code Coverage)

Clone this wiki locally