Teuchos - Trilinos Tools Package Version of the Day
Loading...
Searching...
No Matches
Topics
Unit Testing Support

Topics

 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
Unit testing support.
#define TEST_EQUALITY_CONST(v1, v2)
Assert the equality of v1 and constant v2.
#define TEST_EQUALITY(v1, v2)
Assert the equality of v1 and v2.
#define TEUCHOS_UNIT_TEST(TEST_GROUP, TEST_NAME)
Macro for defining a (non-templated) unit test.

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);
}
A MPI utilities class, providing methods for initializing, finalizing, and querying the global MPI se...
Unit testing support.
Initialize, finalize, and query the global MPI session.
static int runUnitTestsFromMain(int argc, char *argv[])
Run the unit tests from main() passing in (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: