Teuchos - Trilinos Tools Package  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Modules
Unit Testing Support

Modules

 Unit Testing Definition Macros
 
 Unit Testing Assert Macros
 

Detailed Description

Teuchos contains simple but effective native unit testing support. Unit tests can be defined in separate files. This can be as simple as:

// Int_UnitTests.cpp
namespace {
TEUCHOS_UNIT_TEST( Int, Basic )
{
int 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
int main( int argc, char* argv[] )
{
Teuchos::GlobalMPISession mpiSession(&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 indicating which tests passed or failed. 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: