Difference between revisions of "Documentation/Nightly/Developers/QtTesting"

From Slicer Wiki
Jump to: navigation, search
Line 132: Line 132:
  
 
{{ambox
 
{{ambox
| type = speedy
+
| type =
 
| text = 4 files should have been created ! <br>  
 
| text = 4 files should have been created ! <br>  
 
<code>MY_WIDGET_NAMETranslator.cpp <br>  
 
<code>MY_WIDGET_NAMETranslator.cpp <br>  
Line 139: Line 139:
 
MY_WIDGET_NAMEPlayer.h</code><br>Those files are only the basic code. You now have to implement the functions, according to your widget, to record the events<br>Then add those files in the same folder as your widget.
 
MY_WIDGET_NAMEPlayer.h</code><br>Those files are only the basic code. You now have to implement the functions, according to your widget, to record the events<br>Then add those files in the same folder as your widget.
 
}}
 
}}
 
  
 
=Open bugs=
 
=Open bugs=

Revision as of 17:25, 30 May 2012

Home < Documentation < Nightly < Developers < QtTesting

3DSlicerQtTesting.png

Overview

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 test using QtTesting

QtTesting framework can also be use to create module test.
Use the description below, but instead of Slicer4/Applications/SlicerApp/Testing all the path start by Slicer4/Path/To/The/Modules/Testing

Following is the different step to create a test using QtTesting framework.

Create your XML script

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


Create a Python script

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

Create a python file with the following lines

   import slicer
   import slicer.testing
   import slicer.util
   filepath = os.environ['SLICER_HOME'] + 'path/to/xml/script.xml'
   testUtility = slicer.app.testingUtility()
   success = testUtility.playTests(filepath)
   if success :
       slicer.util.exit(EXIT_SUCCESS)
   else:
       slicer.util.exit(EXIT_FAILURE)

Save to the directory Slicer4/Applications/SlicerApp/Testing/Python/Slicer4.X.X_tutorial_MY_TUTORIAL_NAME.py


Add the test in CMake

Adding the test in CMake will allow the test to be run with CTest and will also be run by the dashboard machines every nights.

Edit the file Slicer4/Applications/SlicerApp/Testing/Python/CMakeLists.txt
Add your test at the end of the Slicer_USE_QTTESTING condition:

   if(Slicer_USE_QTTESTING)
     {   
     ...
     slicer_add_python_test(
       SCRIPT pythonScriptName.py
       SLICER_ARGS --launcher-no-splash --qt-testing)
     }


You just wrote a Slicer Unit Test using QtTesting framework !


Run your test

You can either use directly CTest or the pyhton script created.

Using CTest

Linux Mac Windows

You need to open a terminal.
Then type in the terminal:

$ cd path/to/Slicer4-Superbuild/Slicer-build
$ ctest -R MY_TEST_NAME -VV

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

$ cd path\to\Slicer4-Superbuild\Slicer-build
$ path\to\cmake\ctest.exe -R MY_TEST_NAME -VV

Using the python script

Linux Mac Windows

You need to open a terminal.
Then type in the terminal:

$ cd path/to/Slicer4/Application/SlicerApp/Testing/Python
$ python MY_TEST_NAME.py

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

$ cd path\to\Slicer4\Applicaiton\SlicerApp\Testing\Python
$ path\to\Slicer4-Superbuild\python-build\PCBuild\python.exe MY_TEST_NAME.py

Create custom translator/player

After created a custom widget, it might be possible that all its actions are not properly recorded, or played.
QtTesting provides us basic translator and player template, to create our custom translator and player according to the widget.

You can use the following command to create those basic files.

Linux Mac Windows

You need to open a terminal.
Then type in the terminal:

$ cd path/to/Slicer4-Superbuild/CTK-build/QtTesting/Utilities/Scripts
$ python TranslatorPlayerWizard.py MY_WIDGET_NAME
$ cd ../MY_WIDGET_NAME

You need to open a terminal.
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\TranslatorPlayerWizard.py MY_WIDGET_NAME
$ cd ../MY_WIDGET_NAME

Open bugs

Work in progress, following the two bug trackers :

Slicer issues

QtTesting issues