Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to organize test cases with boost::test library?

I have a project of 50+ .H/.CPP files/classes. I would like to test every class with its own test case, which will include methods for testing of different aspects of every class. My classes are located in different directories, like this:

/project
  /include
    /SuperModule
      Foo.h
      Foo.cpp
      ..
    Alpha.h
    Alpha.cpp
    ..
  /test         // I assume that my tests shall be here
  main.cpp
  Makefile

I would like to use boost::test as a unit-testing framework. How should I organize my files, how shall I name them, etc. Some hint or a link or a suggestion will be appreciated. Thanks.

like image 487
yegor256 Avatar asked Jul 05 '10 15:07

yegor256


People also ask

How do you organize your test cases?

The best and simple way to organize your test document is by splitting it into many single useful sections. Divide the entire testing into multiple test scenarios. Then divide each scenario into multiple tests. Finally, divide each case into multiple test steps.

What is a boost test?

Boost unit testing framework (Boost. Test) is a part of the Boost library. It is a fully-functional and scalable framework, with wide range of assertion macros, XML output, and other features. Boost. Test itself lacks mocking functionality, but it can be combined with stand-alone mocking frameworks such as gmock.


1 Answers

We are using boost::test in a similar layout. Our layout is -

/project
  /include
    /SuperModule
       /Foo
        foo.c
        foo.h
        /foo_unittest
            foo_unittest.c   // note - no separate header file is required 
                             // for boost::test unit test.exe program.

Basic layout rule is to put the unit test for a class in a sub-directory named "foo_unittest" after the class in the same directory as the source code. The advantage to this naming is

  1. The source code and the directory are stored next to each other. So by simple inspection you can see if you have written the unit test or not.
  2. Also, when you copy the source code, it is easy to copy the unit test at the same time.

As our projects are not overly complex (30-50 major classes), this system works for us. If you are running larger projects, I don't think this would be an optimal solution.

like image 101
photo_tom Avatar answered Oct 18 '22 21:10

photo_tom