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

From Slicer Wiki
Jump to: navigation, search
Line 1: Line 1:
 
=Overview=
 
=Overview=
  
==Write a 3DSlicer UnitTest with QtTesting==
+
=Write a 3DSlicer UnitTest with QtTesting=
  
=== 1/ Create your XML script ===
+
== 1/ Create your XML script ==
 
See [http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/SlicerApplication/QtTesting QtTesting user Wiki]
 
See [http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/SlicerApplication/QtTesting QtTesting user Wiki]
 
{{ambox  
 
{{ambox  
 
| type = content
 
| type = content
|text = If your tutorial needs data, please first add the data to the Sample Data module, and use this module during the test. See instruction [http://www.slicer.org/slicerWiki/index.php/SampleData here]
+
|text = If you needs data, please first add the data to the Sample Data module, and use this module during the test. See instruction [http://www.slicer.org/slicerWiki/index.php/SampleData here]
 
}}
 
}}
  
=== 2/ Create a Python script ===
+
== 2/ Create a Python script ==
''This Python test will start 3DSlicer and run your xml script previously recorded''
+
''This Python test will start 3DSlicer and run the previously recorded xml script''
  
 
'''''Create a file with the following code'''''
 
'''''Create a file with the following code'''''
Line 28: Line 28:
 
'''''Save to the directory ''''' <code>${Slicer_SOURCE_DIR}/Applications/SlicerApp/Testing/Python/ </code>
 
'''''Save to the directory ''''' <code>${Slicer_SOURCE_DIR}/Applications/SlicerApp/Testing/Python/ </code>
  
=== 3/ Add the test in CMake ===
+
== 3/ Add the test in CMake ==
 
Edit the file <code>Slicer4/Applications/SlicerApp/Testing/Python/CMakeLists.txt</code><br>
 
Edit the file <code>Slicer4/Applications/SlicerApp/Testing/Python/CMakeLists.txt</code><br>
  

Revision as of 18:06, 24 May 2012

Home < Documentation < Nightly < Developers < QtTesting

Overview

Write a 3DSlicer UnitTest with QtTesting

1/ Create your XML script

See QtTesting user Wiki

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 = slicer.app.testingUtility()
   success = testUtility.playTests(filepath)
   if success :
       slicer.util.exit(EXIT_SUCCESS)
   else:
       slicer.util.exit(EXIT_FAILURE)

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:

   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 !

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
$ python TranslatorPlayerWizard.py MY_MODULE_NAME
$ cd ../yourClassName/

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\ModuleWizard.py MY_MODULE_NAME
$ cd ../yourClassName

4 files should have been created !

Open bugs

Slicer issues

QtTesting issues