From Slicer Wiki
Jump to: navigation, search
Home < Documentation < Nightly < Developers < QtTesting


QtTesting provides us a testing framework to test our application. It complements unit tests, by testing the application in its globality.

Following is a step by step guide to create slicer unit test, or module unit test, using this framework, which can be run as part of a nightly build automatic testing.

Write a 3DSlicer UnitTest with QtTesting

1/ Create your XML script

See QtTesting user Wiki to know how to create this xml script.
Save the xml script to Slicer4/Application/SlicerApp/Testing/QtTesting/Slicer4.X.X_tutorial_MY_TUTORIAL_NAME.xml

2/ Create a Python script

This Python test will start 3DSlicer and run the previously recorded xml script

Create a file with the following code

   import slicer
   import slicer.testing
   import slicer.util
   filepath = os.environ['SLICER_HOME'] + 'path/to/your/script.xml'
   testUtility =
   success = testUtility.playTests(filepath)
   if success :

Save to the directory ${Slicer_SOURCE_DIR}/Applications/SlicerApp/Testing/Python/

3/ Add the test in CMake

Edit the file Slicer4/Applications/SlicerApp/Testing/Python/CMakeLists.txt

Add your test at the end of the Slicer_USE_QTTESTING condition:

       SLICER_ARGS --launcher-no-splash --qt-testing)

You just wrote a Slicer Unit Test using QtTesting framework !

Create custom translator/player

QTTesting provides us basic translator and player template.
You can use the following command to create those basic files.

Linux Mac Windows

You need to open a terminal and go to the Slicer4 source directory.
Then type in the terminal:

$ cd path/to/Slicer4-Superbuild/CTK-build/QtTesting/Utilities/Scripts

You need to open a terminal and go to the Slicer4 source directory.
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt
Then type in the terminal:

$ cd path\to\Slicer4-Superbuild
$ python-build\PCBuild\python.exe CTK-build\QtTesting\Utilities\Scripts\ MY_WIDGET_NAME

Open bugs

Work in progress, following the two bug trackers :

Slicer issues

QtTesting issues