First Infrastructure for Unit Testing

We put in place the infrastructure to compile and run unit tests. At this moment the only class with unit tests is the SampleLoggger.

The unit tests were developed using Boost Unit Test Framework (UTF)

Setting up the framework

Compiling the tests

The Makefile was updated to include a new targer 'test', so running the following command inside the build folder will compile the tests:

[~/powerdevs/build]$ make test

Running the tests

When succesfully compiled, a new executable file named 'test' is produced in the powerdevs/output folder. Executing that file will execute the unit tests:

[~/powerdevs/$ output/test
Running 11 test cases...

*** No errors detected

Another option is to use the Eclipse Boost UTF runner that comes with CDT. This will show the result of each test, error, messages, etc.
This can be easily configured in the "Run Configurations" inside eclipse. You create a new "C/C++ Unit" run configuration pointing to the test executable, and then choose "Boost Test Runner" in the "C/C++ Testing" tab.

Developing tests

All unit tests are located in the Powerdevs/atomic/unitTest folder. (maybe there should be a better place!!!). Inside this folder you will find:

  1. Makefile.include: this is included when compiling tests. It defines the necesary dependencies, and it is set to compile in debug mode.
  2. main.cpp: this is the main entry point for the unit tests. The main function is defined by BOOST with the BOOST_TEST_MODULE macro
    If you want to add tests for new classes, you will have to add an #include to the test suite you developed
  3. MockClasses.h: defines some Mock classes to use in tests (ej: MockSimulator). TODO: evaluate using to create mocks easily
  4. <className>Test.cpp: All test suits (all tests for a single class) are defined in .cpp files with the name <className>Test.cpp.
    In this file the BOOST_AUTO_TEST_SUITE macro should be called with the same of the suite. New tests can be defined with BOOST_AUTO_TEST_CASE macro.
    See the SamplerLoggerTest.cpp as an example.
For more information on how to develop unit tests using Boost UTF refer to the Boost documentation:

Functional tests

The FunctionalTestRootSimulator is a roo simulator that facilitates creatign functional tests. It creates a tester model with the same ports as the testSubject model (which is passed in the constructor):

Example of how to use the FunctionalTestRootSimulator

Future ideas for DEVS automated tests

There are 2 kind of automated tests that can be used for atomic models: 1) unit tests, to test the internal code and logic 2) functional tests, just checking the the output of the model.

Both kind of tests can be done using the infrastructure above: automated tests using mocks.

  • Mocks for coupledModel, simulator should be developed to allow for these tests
    • For functional tests one option is develop test cases within an atomic model. Have a coupled model with 2 atomics: one is the test subject, the other the tester. The tester sends messages and asserts on received messages. The coupled model could be automatically generated.
    • Another option is to have a mockCoupled and to directly do assertions there. It is the coupled the one sending messages to the test subject, and cheking its outputs.
    • For unit tests, a mock simulator should be developed to inteact with the test subject atomic model.
  • A high level language (as described in the picture) could be developed to generate the code for the tests

-- MatiasAlejandroBonaventura - 2016-06-21

Edit | Attach | Watch | Print version | History: r4 < r3 < r2 < r1 | Backlinks | Raw View | WYSIWYG | More topic actions
Topic revision: r4 - 2016-09-16 - MatiasAlejandroBonaventura
    • Cern Search Icon Cern Search
    • TWiki Search Icon TWiki Search
    • Google Search Icon Google Search

    Main All webs login

This site is powered by the TWiki collaboration platform Powered by PerlCopyright & 2008-2019 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback