Teuchos - Trilinos Tools Package Version of the Day
Modules
Unit Testing Support

Modules

 Unit Testing Definition Macros
 Unit Testing Assert Macros

Detailed Description

Teuchos contains a simple but very effective native unit testing support code.

Unit tests can be defined in separate files which can be as simple as:

// Int_UnitTests.cpp

#include "Teuchos_UnitTestHarness.hpp"

namespace {

TEUCHOS_UNIT_TEST( Int, Basic )
{
  int i1 = 5;
  TEST_EQUALITY_CONST( i1, 5 );
}

TEUCHOS_UNIT_TEST( Int, Assignment )
{
  int i1 = 4;
  int i2 = i1;
  TEST_EQUALITY( i2, i1 );
}

} // namespace

and then compiled along with other unit testing definition files into executables along with a simple main function like:

// UnitTestMain.cpp

#include "Teuchos_UnitTestRepository.hpp"
#include "Teuchos_GlobalMPISession.hpp"

int main( int argc, char* argv[] )
{
  Teuchos::GlobalMPISession mpiSession(&argc, &argv);
  return Teuchos::UnitTestRepository::runUnitTestsFromMain(argc, argv);
}

using CMake code like:

PACKAGE_ADD_EXECUTABLE_AND_TEST(
  MyUnitTests
  SOURCES
    UnitTestMain.cpp
    Int_UnitTests.cpp
    ... other unit test files ...
  STANDARD_PASS_OUTPUT
  )

Once the Unit test exectuable is built, it will run with CTest automatically and produce output and pass/fail. It is just run as:

  ./MyPackage_MyUnitTest.exe

One of the most useful properties of this simple unit testing support code is that the unit testing exectuable (created by the above CMake code) accepts command-line arguments for showing more or less output, runing only particular sets of tests, etc. Just pass in the --help flag to see all of the options as:

  ./MyPackage_MyUnitTest.exe --help

Now learn about unit tests, for example, at:

http://www.oreillynet.com/pub/a/oreilly/oracle/utplsql/news/fulldoc.html

References for Teuchos Unit Testing Support:

Suggestions for unit testing:

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines