Testing

This CMake module provides functions to interface gtest with ctest.

qi_create_test

qi_create_test(name [SRC <src> ...]
    [DEPENDS <depends> ...]
    [TIMEOUT <timeout>]
    [ARGUMENTS <arguments> ...]
    [INSTALL]
    [<remaining args> ...]
)
Arguments:
  • name – the name of the test and the target
  • SRC – sources of the test
  • DEPENDS – the dependencies of the test
  • TIMEOUT – the timeout of the test
  • ARGUMENTS – arguments to be passed to the executable
  • INSTALL – wether the test should be installed (false by default)
  • args (remaining) – source files (will be merged with the SRC group of arguments)

Create a new test. Note that the resulting executable will NOT be installed by default. The name of the test will match the target name

qi_create_gtest

qi_create_gtest(name [NO_ADD_TEST]
    [<remaining args> ...]
    [TIMEOUT <timeout>]
    [SRC <src> ...]
    [DEPENDS <depends> ...]
    [ARGUMENTS <arguments> ...]
)
Arguments:
  • name – name of the test
  • NO_ADD_TEST – Do not call add_test, just create the binary
  • args (remaining) – source files, like the SRC group, argn and SRC will be merged
  • TIMEOUT – The timeout of the test
  • SRC – Sources
  • DEPENDS – Dependencies to pass to use_lib
  • ARGUMENTS – Arguments to pass to add_test (to your test program)

This compiles and add_test’s a CTest test that uses gtest. (so that the test can be run by CTest)

When running ctest, an XML xUnit xml file wiil be created to ${CMAKE_SOURCE_DIR}/test-results/${test_name}.xml

The name of the test will always be the name of the target.

qi_add_test

qi_add_test(test_name target_name [TIMEOUT <timeout>]
    [ARGUMENTS <arguments> ...]
)
Arguments:
  • test_name – The name of the test
  • target_name – The name of the binary to use
  • TIMEOUT – The timeout of the test
  • ARGUMENTS – Arguments to be passed to the executable

Add a test using a binary that was created by qi_create_bin This calls add_test() with the same arguements but:

  • We look for the binary in sdk/bin, and we know there is a _d when using Visual Studio
  • We set a ‘tests’ folder property
  • We make sure necessary environment variables are set on mac

This is a low-level function, you should rather use qi_create_test or qi_create_gtest instead.