https://www.slicer.org/w/api.php?action=feedcontributions&user=BenjaminLong&feedformat=atomSlicer Wiki - User contributions [en]2024-03-29T14:26:20ZUser contributionsMediaWiki 1.33.0https://www.slicer.org/w/index.php?title=Documentation/Nightly/Developers/QtTesting&diff=27518Documentation/Nightly/Developers/QtTesting2012-06-25T20:04:27Z<p>BenjaminLong: /* How QtTesting and CTK work */</p>
<hr />
<div>{|width="100%"<br />
|<br />
__TOC__<br />
|align="right"|<br />
[[Image: 3DSlicerQtTesting.png]]<br />
|}<br />
=Overview=<br />
<br />
QtTesting provides us a testing framework to test our application. It complements unit tests, by testing the application in its globality.<br />
<br />
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.<br><br />
<br />
=Rules for Developers=<br />
<br />
QtTesting records high level events, and try to not record mouse events as mouse press, release or move.<br><br />
Furthermore, QtTesting is still under heavy development and some low level events won't be properly recorded.<br><br />
<br />
'''Please be aware of those following warning :''' <br />
<br />
* Use '''''"activated"''''' signal instead of '''''"clicked"''''', when connection Qt views<br />
<br />
=How QtTesting and CTK work=<br />
<br />
{|width="100%"<br />
|align="left"|<br />
[[Image: ctkQtTestingSchemaPlay.png|550px|]]<br />
|align="left"|<br />
[[Image: ctkQtTestingSchemaRecord.png|550px]]<br />
|-<br />
|'''''How it works :'''''<br />
When pqTestUtility starts the playback, it calls pqEvenDispatcher to play a specific script. Then<br />
pqEventDispatcher finds an eventSource able to read the script. Then pqEventDispatcher forwards each<br />
event to the pqEventPlayer. Finally, this last class tries to find the best player to playback the action into the<br />
application. If the action has been done, we start over and over the same process until the end. If there is<br />
one error, or an action couldn’t be handled, the player fails with an error.<br />
|'''''How it works :'''''<br />
When pqTestUtility starts to record events, it finds the observer which will write the file, creates the file,<br />
and starts the pqEventRecorder.<br />
Then every time there is a user action in the application, a specific translator will catch it and transform it<br />
into an high level event. This high level event is sent to the pqEventTranslator, and then to the<br />
pqEventObserver which writes the action recorded into a specific language, XML for example.<br />
|}<br />
<br />
=Write a 3DSlicer test using QtTesting=<br />
<br />
QtTesting framework can also be use to create module test.<br> Use the description below, but instead of <code>Slicer/Applications/SlicerApp/Testing</code> all the path start by <code>Slicer/Path/To/The/Modules/Testing</code><br />
<br />
Following is the different step to create a test using QtTesting framework. <br />
<br />
== Create your XML script ==<br />
See [http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/SlicerApplication/QtTesting QtTesting user Wiki] to know how to create this xml script.<br><br />
'''Save the xml script to''' <code>Slicer/Applications/SlicerApp/Data/Input/MYTUTORIALNAME.xml''</code><br><br />
{{ambox <br />
| type = content<br />
|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]<br><br />
[[Documentation/{{documentation/version}}/Modules/SampleData Sample Data]] module according to the current Slicer version<br />
}}<br />
<br />
== Create a Python script ==<br />
''This Python test will start 3DSlicer and run the previously recorded xml script''<br />
<br />
'''''Create a python file with the following lines'''''<br />
<br />
import os<br />
import slicer<br />
import ApplicationsSlicerAppData as data<br />
filepath = data.input + '/MYTUTORIALNAME.xml') ex : NeurosurgicalPlanningTutorial.xml<br />
testUtility = slicer.app.testingUtility()<br />
success = testUtility.playTests(filepath)<br />
if not success :<br />
raise Exception('Failed to finished properly the play back !')<br />
<br />
'''''Save to the directory ''''' <code>Slicer/Applications/SlicerApp/Testing/Python/MYTUTORIALNAME.py </code><br />
<br />
== Add the test in CMake ==<br />
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.<br />
<br />
Edit the file <code>Slicer/Applications/SlicerApp/Testing/Python/CMakeLists.txt</code><br><br />
Add your test at the end of the Slicer_USE_QTTESTING condition and add the name in the <code>set_tests_properties</code> function :<br />
<br />
if(Slicer_USE_QTTESTING)<br />
{ <br />
...<br />
slicer_add_python_test(<br />
SCRIPT MYTUTORIALNAME.py<br />
SLICER_ARGS --launcher-no-splash --qt-testing)<br />
set_tests_properties(<br />
py_NeurosurgicalPlanningTutorial<br />
py_DiffusionTensorImagingTutorial<br />
....<br />
py_MYTUTORIALNAME<br />
...<br />
PROPERTIES RUN_SERIAL ON<br />
)<br />
}<br />
<br />
<br />
You just wrote a Slicer Unit Test using QtTesting framework !<br />
<br />
== Run your test==<br />
<br />
You can either use directly CTest or the pyhton script created.<br />
<br />
===Using CTest===<br />
{|width = "100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer-Superbuild/Slicer-build<br />
$ ctest -R MYTUTORIALNAME -VV<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer-Superbuild\Slicer-build<br />
$ path\to\cmake\ctest.exe -R MYTUTORIALNAME -VV<br />
|}<br />
<br />
===Using the python script===<br />
{|width="100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer/Application/SlicerApp/Testing/Python<br />
$ python MYTUTORIALNAME.py<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer\Applicaiton\SlicerApp\Testing\Python<br />
$ path\to\Slicer-Superbuild\python-build\PCBuild\python.exe MYTUTORIALNAME.py<br />
|}<br />
<br />
=Create custom translator/player=<br />
<br />
After created a custom widget, it might be possible that all its actions are not properly recorded, or played.<br><br />
QtTesting provides us basic translator and player template, to create our custom translator and player according to the widget. <br><br />
<br />
You can use the following command to create those basic files.<br />
<br />
{|width="100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer-Superbuild/CTK-build/QtTesting/Utilities/Scripts<br />
$ python TranslatorPlayerWizard.py MY_WIDGET_NAME<br />
$ cd ../MY_WIDGET_NAME<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer-Superbuild<br />
$ python-build\PCBuild\python.exe CTK-build\QtTesting\Utilities\Scripts\TranslatorPlayerWizard.py MY_WIDGET_NAME<br />
$ cd ../MY_WIDGET_NAME<br />
|}<br />
<br />
{{ambox<br />
| type = <br />
| text = 4 files should have been created ! <br> <br />
<code>MY_WIDGET_NAMETranslator.cpp <br> <br />
MY_WIDGET_NAMETranslator.h <br> <br />
MY_WIDGET_NAMEPlayer.cpp <br> <br />
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.<br />
}}<br />
<br />
Finally move the 4 files to the same directory as your widget<br />
<br />
$ cd path/to/Slicer-Superbuild/CTK-build/QtTesting/Utilities/MY_WIDGET_NAME<br />
$ mv MY_WIDGET_NAMETranslator.cpp MY_WIDGET_NAMETranslator.h MY_WIDGET_NAMEPlayer.cpp MY_WIDGET_NAMEPlayer.h Path/To/My/Widget/Directory<br />
<br />
or just a simple copy to the same directory as your widget<br />
<br />
$ cp MY_WIDGET_NAMETranslator.cpp MY_WIDGET_NAMETranslator.h MY_WIDGET_NAMEPlayer.cpp MY_WIDGET_NAMEPlayer.h Path/To/My/Widget/Directory<br />
<br />
=Open bugs=<br />
Work in progress, following the two bug trackers :<br />
<br />
[http://na-mic.org/Mantis/search.php?project_id=3&category=QtTesting&sticky_issues=off&sortby=last_updated&dir=DESC&hide_status_id=-2 Slicer issues]<br />
<br />
[https://github.com/commontk/CTK/issues?labels=Testing&milestone=&page=1&state=open QtTesting issues]</div>BenjaminLonghttps://www.slicer.org/w/index.php?title=Documentation/Nightly/Developers/QtTesting&diff=27517Documentation/Nightly/Developers/QtTesting2012-06-25T20:01:15Z<p>BenjaminLong: /* How QtTesting and CTK work */</p>
<hr />
<div>{|width="100%"<br />
|<br />
__TOC__<br />
|align="right"|<br />
[[Image: 3DSlicerQtTesting.png]]<br />
|}<br />
=Overview=<br />
<br />
QtTesting provides us a testing framework to test our application. It complements unit tests, by testing the application in its globality.<br />
<br />
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.<br><br />
<br />
=Rules for Developers=<br />
<br />
QtTesting records high level events, and try to not record mouse events as mouse press, release or move.<br><br />
Furthermore, QtTesting is still under heavy development and some low level events won't be properly recorded.<br><br />
<br />
'''Please be aware of those following warning :''' <br />
<br />
* Use '''''"activated"''''' signal instead of '''''"clicked"''''', when connection Qt views<br />
<br />
=How QtTesting and CTK work=<br />
<br />
{|width="100%"<br />
|align="left"|<br />
[[Image: ctkQtTestingSchemaPlay.png|600px|]]<br />
|align="right"|<br />
[[Image: ctkQtTestingSchemaRecord.png|600px]]<br />
|-<br />
|'''''How it works :'''''<br />
When pqTestUtility starts the playback, it calls pqEvenDispatcher to play a specific script. Then<br />
pqEventDispatcher finds an eventSource able to read the script. Then pqEventDispatcher forwards each<br />
event to the pqEventPlayer. Finally, this last class tries to find the best player to playback the action into the<br />
application. If the action has been done, we start over and over the same process until the end. If there is<br />
one error, or an action couldn’t be handled, the player fails with an error.<br />
|'''''How it works :'''''<br />
When pqTestUtility starts to record events, it finds the observer which will write the file, creates the file,<br />
and starts the pqEventRecorder.<br />
Then every time there is a user action in the application, a specific translator will catch it and transform it<br />
into an high level event. This high level event is sent to the pqEventTranslator, and then to the<br />
pqEventObserver which writes the action recorded into a specific language, XML for example.<br />
|}<br />
<br />
=Write a 3DSlicer test using QtTesting=<br />
<br />
QtTesting framework can also be use to create module test.<br> Use the description below, but instead of <code>Slicer/Applications/SlicerApp/Testing</code> all the path start by <code>Slicer/Path/To/The/Modules/Testing</code><br />
<br />
Following is the different step to create a test using QtTesting framework. <br />
<br />
== Create your XML script ==<br />
See [http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/SlicerApplication/QtTesting QtTesting user Wiki] to know how to create this xml script.<br><br />
'''Save the xml script to''' <code>Slicer/Applications/SlicerApp/Data/Input/MYTUTORIALNAME.xml''</code><br><br />
{{ambox <br />
| type = content<br />
|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]<br><br />
[[Documentation/{{documentation/version}}/Modules/SampleData Sample Data]] module according to the current Slicer version<br />
}}<br />
<br />
== Create a Python script ==<br />
''This Python test will start 3DSlicer and run the previously recorded xml script''<br />
<br />
'''''Create a python file with the following lines'''''<br />
<br />
import os<br />
import slicer<br />
import ApplicationsSlicerAppData as data<br />
filepath = data.input + '/MYTUTORIALNAME.xml') ex : NeurosurgicalPlanningTutorial.xml<br />
testUtility = slicer.app.testingUtility()<br />
success = testUtility.playTests(filepath)<br />
if not success :<br />
raise Exception('Failed to finished properly the play back !')<br />
<br />
'''''Save to the directory ''''' <code>Slicer/Applications/SlicerApp/Testing/Python/MYTUTORIALNAME.py </code><br />
<br />
== Add the test in CMake ==<br />
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.<br />
<br />
Edit the file <code>Slicer/Applications/SlicerApp/Testing/Python/CMakeLists.txt</code><br><br />
Add your test at the end of the Slicer_USE_QTTESTING condition and add the name in the <code>set_tests_properties</code> function :<br />
<br />
if(Slicer_USE_QTTESTING)<br />
{ <br />
...<br />
slicer_add_python_test(<br />
SCRIPT MYTUTORIALNAME.py<br />
SLICER_ARGS --launcher-no-splash --qt-testing)<br />
set_tests_properties(<br />
py_NeurosurgicalPlanningTutorial<br />
py_DiffusionTensorImagingTutorial<br />
....<br />
py_MYTUTORIALNAME<br />
...<br />
PROPERTIES RUN_SERIAL ON<br />
)<br />
}<br />
<br />
<br />
You just wrote a Slicer Unit Test using QtTesting framework !<br />
<br />
== Run your test==<br />
<br />
You can either use directly CTest or the pyhton script created.<br />
<br />
===Using CTest===<br />
{|width = "100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer-Superbuild/Slicer-build<br />
$ ctest -R MYTUTORIALNAME -VV<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer-Superbuild\Slicer-build<br />
$ path\to\cmake\ctest.exe -R MYTUTORIALNAME -VV<br />
|}<br />
<br />
===Using the python script===<br />
{|width="100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer/Application/SlicerApp/Testing/Python<br />
$ python MYTUTORIALNAME.py<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer\Applicaiton\SlicerApp\Testing\Python<br />
$ path\to\Slicer-Superbuild\python-build\PCBuild\python.exe MYTUTORIALNAME.py<br />
|}<br />
<br />
=Create custom translator/player=<br />
<br />
After created a custom widget, it might be possible that all its actions are not properly recorded, or played.<br><br />
QtTesting provides us basic translator and player template, to create our custom translator and player according to the widget. <br><br />
<br />
You can use the following command to create those basic files.<br />
<br />
{|width="100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer-Superbuild/CTK-build/QtTesting/Utilities/Scripts<br />
$ python TranslatorPlayerWizard.py MY_WIDGET_NAME<br />
$ cd ../MY_WIDGET_NAME<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer-Superbuild<br />
$ python-build\PCBuild\python.exe CTK-build\QtTesting\Utilities\Scripts\TranslatorPlayerWizard.py MY_WIDGET_NAME<br />
$ cd ../MY_WIDGET_NAME<br />
|}<br />
<br />
{{ambox<br />
| type = <br />
| text = 4 files should have been created ! <br> <br />
<code>MY_WIDGET_NAMETranslator.cpp <br> <br />
MY_WIDGET_NAMETranslator.h <br> <br />
MY_WIDGET_NAMEPlayer.cpp <br> <br />
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.<br />
}}<br />
<br />
Finally move the 4 files to the same directory as your widget<br />
<br />
$ cd path/to/Slicer-Superbuild/CTK-build/QtTesting/Utilities/MY_WIDGET_NAME<br />
$ mv MY_WIDGET_NAMETranslator.cpp MY_WIDGET_NAMETranslator.h MY_WIDGET_NAMEPlayer.cpp MY_WIDGET_NAMEPlayer.h Path/To/My/Widget/Directory<br />
<br />
or just a simple copy to the same directory as your widget<br />
<br />
$ cp MY_WIDGET_NAMETranslator.cpp MY_WIDGET_NAMETranslator.h MY_WIDGET_NAMEPlayer.cpp MY_WIDGET_NAMEPlayer.h Path/To/My/Widget/Directory<br />
<br />
=Open bugs=<br />
Work in progress, following the two bug trackers :<br />
<br />
[http://na-mic.org/Mantis/search.php?project_id=3&category=QtTesting&sticky_issues=off&sortby=last_updated&dir=DESC&hide_status_id=-2 Slicer issues]<br />
<br />
[https://github.com/commontk/CTK/issues?labels=Testing&milestone=&page=1&state=open QtTesting issues]</div>BenjaminLonghttps://www.slicer.org/w/index.php?title=Documentation/Nightly/Developers/QtTesting&diff=27516Documentation/Nightly/Developers/QtTesting2012-06-25T19:54:39Z<p>BenjaminLong: /* How QtTesting and CTK work */</p>
<hr />
<div>{|width="100%"<br />
|<br />
__TOC__<br />
|align="right"|<br />
[[Image: 3DSlicerQtTesting.png]]<br />
|}<br />
=Overview=<br />
<br />
QtTesting provides us a testing framework to test our application. It complements unit tests, by testing the application in its globality.<br />
<br />
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.<br><br />
<br />
=Rules for Developers=<br />
<br />
QtTesting records high level events, and try to not record mouse events as mouse press, release or move.<br><br />
Furthermore, QtTesting is still under heavy development and some low level events won't be properly recorded.<br><br />
<br />
'''Please be aware of those following warning :''' <br />
<br />
* Use '''''"activated"''''' signal instead of '''''"clicked"''''', when connection Qt views<br />
<br />
=How QtTesting and CTK work=<br />
<br />
{|width="100%"<br />
|align="left"|<br />
[[Image: ctkQtTestingSchemaPlay.png|600px|]]<br />
|align="right"|<br />
[[Image: ctkQtTestingSchemaRecord.png|600px]]<br />
|}<br />
<br />
=Write a 3DSlicer test using QtTesting=<br />
<br />
QtTesting framework can also be use to create module test.<br> Use the description below, but instead of <code>Slicer/Applications/SlicerApp/Testing</code> all the path start by <code>Slicer/Path/To/The/Modules/Testing</code><br />
<br />
Following is the different step to create a test using QtTesting framework. <br />
<br />
== Create your XML script ==<br />
See [http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/SlicerApplication/QtTesting QtTesting user Wiki] to know how to create this xml script.<br><br />
'''Save the xml script to''' <code>Slicer/Applications/SlicerApp/Data/Input/MYTUTORIALNAME.xml''</code><br><br />
{{ambox <br />
| type = content<br />
|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]<br><br />
[[Documentation/{{documentation/version}}/Modules/SampleData Sample Data]] module according to the current Slicer version<br />
}}<br />
<br />
== Create a Python script ==<br />
''This Python test will start 3DSlicer and run the previously recorded xml script''<br />
<br />
'''''Create a python file with the following lines'''''<br />
<br />
import os<br />
import slicer<br />
import ApplicationsSlicerAppData as data<br />
filepath = data.input + '/MYTUTORIALNAME.xml') ex : NeurosurgicalPlanningTutorial.xml<br />
testUtility = slicer.app.testingUtility()<br />
success = testUtility.playTests(filepath)<br />
if not success :<br />
raise Exception('Failed to finished properly the play back !')<br />
<br />
'''''Save to the directory ''''' <code>Slicer/Applications/SlicerApp/Testing/Python/MYTUTORIALNAME.py </code><br />
<br />
== Add the test in CMake ==<br />
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.<br />
<br />
Edit the file <code>Slicer/Applications/SlicerApp/Testing/Python/CMakeLists.txt</code><br><br />
Add your test at the end of the Slicer_USE_QTTESTING condition and add the name in the <code>set_tests_properties</code> function :<br />
<br />
if(Slicer_USE_QTTESTING)<br />
{ <br />
...<br />
slicer_add_python_test(<br />
SCRIPT MYTUTORIALNAME.py<br />
SLICER_ARGS --launcher-no-splash --qt-testing)<br />
set_tests_properties(<br />
py_NeurosurgicalPlanningTutorial<br />
py_DiffusionTensorImagingTutorial<br />
....<br />
py_MYTUTORIALNAME<br />
...<br />
PROPERTIES RUN_SERIAL ON<br />
)<br />
}<br />
<br />
<br />
You just wrote a Slicer Unit Test using QtTesting framework !<br />
<br />
== Run your test==<br />
<br />
You can either use directly CTest or the pyhton script created.<br />
<br />
===Using CTest===<br />
{|width = "100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer-Superbuild/Slicer-build<br />
$ ctest -R MYTUTORIALNAME -VV<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer-Superbuild\Slicer-build<br />
$ path\to\cmake\ctest.exe -R MYTUTORIALNAME -VV<br />
|}<br />
<br />
===Using the python script===<br />
{|width="100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer/Application/SlicerApp/Testing/Python<br />
$ python MYTUTORIALNAME.py<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer\Applicaiton\SlicerApp\Testing\Python<br />
$ path\to\Slicer-Superbuild\python-build\PCBuild\python.exe MYTUTORIALNAME.py<br />
|}<br />
<br />
=Create custom translator/player=<br />
<br />
After created a custom widget, it might be possible that all its actions are not properly recorded, or played.<br><br />
QtTesting provides us basic translator and player template, to create our custom translator and player according to the widget. <br><br />
<br />
You can use the following command to create those basic files.<br />
<br />
{|width="100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer-Superbuild/CTK-build/QtTesting/Utilities/Scripts<br />
$ python TranslatorPlayerWizard.py MY_WIDGET_NAME<br />
$ cd ../MY_WIDGET_NAME<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer-Superbuild<br />
$ python-build\PCBuild\python.exe CTK-build\QtTesting\Utilities\Scripts\TranslatorPlayerWizard.py MY_WIDGET_NAME<br />
$ cd ../MY_WIDGET_NAME<br />
|}<br />
<br />
{{ambox<br />
| type = <br />
| text = 4 files should have been created ! <br> <br />
<code>MY_WIDGET_NAMETranslator.cpp <br> <br />
MY_WIDGET_NAMETranslator.h <br> <br />
MY_WIDGET_NAMEPlayer.cpp <br> <br />
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.<br />
}}<br />
<br />
Finally move the 4 files to the same directory as your widget<br />
<br />
$ cd path/to/Slicer-Superbuild/CTK-build/QtTesting/Utilities/MY_WIDGET_NAME<br />
$ mv MY_WIDGET_NAMETranslator.cpp MY_WIDGET_NAMETranslator.h MY_WIDGET_NAMEPlayer.cpp MY_WIDGET_NAMEPlayer.h Path/To/My/Widget/Directory<br />
<br />
or just a simple copy to the same directory as your widget<br />
<br />
$ cp MY_WIDGET_NAMETranslator.cpp MY_WIDGET_NAMETranslator.h MY_WIDGET_NAMEPlayer.cpp MY_WIDGET_NAMEPlayer.h Path/To/My/Widget/Directory<br />
<br />
=Open bugs=<br />
Work in progress, following the two bug trackers :<br />
<br />
[http://na-mic.org/Mantis/search.php?project_id=3&category=QtTesting&sticky_issues=off&sortby=last_updated&dir=DESC&hide_status_id=-2 Slicer issues]<br />
<br />
[https://github.com/commontk/CTK/issues?labels=Testing&milestone=&page=1&state=open QtTesting issues]</div>BenjaminLonghttps://www.slicer.org/w/index.php?title=File:CtkQtTestingSchemaRecord.png&diff=27515File:CtkQtTestingSchemaRecord.png2012-06-25T19:51:47Z<p>BenjaminLong: </p>
<hr />
<div></div>BenjaminLonghttps://www.slicer.org/w/index.php?title=File:CtkQtTestingSchemaPlay.png&diff=27514File:CtkQtTestingSchemaPlay.png2012-06-25T19:51:27Z<p>BenjaminLong: </p>
<hr />
<div></div>BenjaminLonghttps://www.slicer.org/w/index.php?title=Documentation/Nightly/Developers/QtTesting&diff=27513Documentation/Nightly/Developers/QtTesting2012-06-25T19:50:23Z<p>BenjaminLong: /* How QtTesting and CTK work */</p>
<hr />
<div>{|width="100%"<br />
|<br />
__TOC__<br />
|align="right"|<br />
[[Image: 3DSlicerQtTesting.png]]<br />
|}<br />
=Overview=<br />
<br />
QtTesting provides us a testing framework to test our application. It complements unit tests, by testing the application in its globality.<br />
<br />
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.<br><br />
<br />
=Rules for Developers=<br />
<br />
QtTesting records high level events, and try to not record mouse events as mouse press, release or move.<br><br />
Furthermore, QtTesting is still under heavy development and some low level events won't be properly recorded.<br><br />
<br />
'''Please be aware of those following warning :''' <br />
<br />
* Use '''''"activated"''''' signal instead of '''''"clicked"''''', when connection Qt views<br />
<br />
=How QtTesting and CTK work=<br />
<br />
{|width="100%"<br />
|align="left"|<br />
[[Image: ctkQtTestingSchemaPlay.png]]<br />
|align="right"|<br />
[[Image: ctkQtTestingSchemaRecord.png]]<br />
|}<br />
<br />
=Write a 3DSlicer test using QtTesting=<br />
<br />
QtTesting framework can also be use to create module test.<br> Use the description below, but instead of <code>Slicer/Applications/SlicerApp/Testing</code> all the path start by <code>Slicer/Path/To/The/Modules/Testing</code><br />
<br />
Following is the different step to create a test using QtTesting framework. <br />
<br />
== Create your XML script ==<br />
See [http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/SlicerApplication/QtTesting QtTesting user Wiki] to know how to create this xml script.<br><br />
'''Save the xml script to''' <code>Slicer/Applications/SlicerApp/Data/Input/MYTUTORIALNAME.xml''</code><br><br />
{{ambox <br />
| type = content<br />
|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]<br><br />
[[Documentation/{{documentation/version}}/Modules/SampleData Sample Data]] module according to the current Slicer version<br />
}}<br />
<br />
== Create a Python script ==<br />
''This Python test will start 3DSlicer and run the previously recorded xml script''<br />
<br />
'''''Create a python file with the following lines'''''<br />
<br />
import os<br />
import slicer<br />
import ApplicationsSlicerAppData as data<br />
filepath = data.input + '/MYTUTORIALNAME.xml') ex : NeurosurgicalPlanningTutorial.xml<br />
testUtility = slicer.app.testingUtility()<br />
success = testUtility.playTests(filepath)<br />
if not success :<br />
raise Exception('Failed to finished properly the play back !')<br />
<br />
'''''Save to the directory ''''' <code>Slicer/Applications/SlicerApp/Testing/Python/MYTUTORIALNAME.py </code><br />
<br />
== Add the test in CMake ==<br />
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.<br />
<br />
Edit the file <code>Slicer/Applications/SlicerApp/Testing/Python/CMakeLists.txt</code><br><br />
Add your test at the end of the Slicer_USE_QTTESTING condition and add the name in the <code>set_tests_properties</code> function :<br />
<br />
if(Slicer_USE_QTTESTING)<br />
{ <br />
...<br />
slicer_add_python_test(<br />
SCRIPT MYTUTORIALNAME.py<br />
SLICER_ARGS --launcher-no-splash --qt-testing)<br />
set_tests_properties(<br />
py_NeurosurgicalPlanningTutorial<br />
py_DiffusionTensorImagingTutorial<br />
....<br />
py_MYTUTORIALNAME<br />
...<br />
PROPERTIES RUN_SERIAL ON<br />
)<br />
}<br />
<br />
<br />
You just wrote a Slicer Unit Test using QtTesting framework !<br />
<br />
== Run your test==<br />
<br />
You can either use directly CTest or the pyhton script created.<br />
<br />
===Using CTest===<br />
{|width = "100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer-Superbuild/Slicer-build<br />
$ ctest -R MYTUTORIALNAME -VV<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer-Superbuild\Slicer-build<br />
$ path\to\cmake\ctest.exe -R MYTUTORIALNAME -VV<br />
|}<br />
<br />
===Using the python script===<br />
{|width="100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer/Application/SlicerApp/Testing/Python<br />
$ python MYTUTORIALNAME.py<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer\Applicaiton\SlicerApp\Testing\Python<br />
$ path\to\Slicer-Superbuild\python-build\PCBuild\python.exe MYTUTORIALNAME.py<br />
|}<br />
<br />
=Create custom translator/player=<br />
<br />
After created a custom widget, it might be possible that all its actions are not properly recorded, or played.<br><br />
QtTesting provides us basic translator and player template, to create our custom translator and player according to the widget. <br><br />
<br />
You can use the following command to create those basic files.<br />
<br />
{|width="100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer-Superbuild/CTK-build/QtTesting/Utilities/Scripts<br />
$ python TranslatorPlayerWizard.py MY_WIDGET_NAME<br />
$ cd ../MY_WIDGET_NAME<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer-Superbuild<br />
$ python-build\PCBuild\python.exe CTK-build\QtTesting\Utilities\Scripts\TranslatorPlayerWizard.py MY_WIDGET_NAME<br />
$ cd ../MY_WIDGET_NAME<br />
|}<br />
<br />
{{ambox<br />
| type = <br />
| text = 4 files should have been created ! <br> <br />
<code>MY_WIDGET_NAMETranslator.cpp <br> <br />
MY_WIDGET_NAMETranslator.h <br> <br />
MY_WIDGET_NAMEPlayer.cpp <br> <br />
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.<br />
}}<br />
<br />
Finally move the 4 files to the same directory as your widget<br />
<br />
$ cd path/to/Slicer-Superbuild/CTK-build/QtTesting/Utilities/MY_WIDGET_NAME<br />
$ mv MY_WIDGET_NAMETranslator.cpp MY_WIDGET_NAMETranslator.h MY_WIDGET_NAMEPlayer.cpp MY_WIDGET_NAMEPlayer.h Path/To/My/Widget/Directory<br />
<br />
or just a simple copy to the same directory as your widget<br />
<br />
$ cp MY_WIDGET_NAMETranslator.cpp MY_WIDGET_NAMETranslator.h MY_WIDGET_NAMEPlayer.cpp MY_WIDGET_NAMEPlayer.h Path/To/My/Widget/Directory<br />
<br />
=Open bugs=<br />
Work in progress, following the two bug trackers :<br />
<br />
[http://na-mic.org/Mantis/search.php?project_id=3&category=QtTesting&sticky_issues=off&sortby=last_updated&dir=DESC&hide_status_id=-2 Slicer issues]<br />
<br />
[https://github.com/commontk/CTK/issues?labels=Testing&milestone=&page=1&state=open QtTesting issues]</div>BenjaminLonghttps://www.slicer.org/w/index.php?title=Documentation/Nightly/Developers/QtTesting&diff=27512Documentation/Nightly/Developers/QtTesting2012-06-25T19:47:08Z<p>BenjaminLong: </p>
<hr />
<div>{|width="100%"<br />
|<br />
__TOC__<br />
|align="right"|<br />
[[Image: 3DSlicerQtTesting.png]]<br />
|}<br />
=Overview=<br />
<br />
QtTesting provides us a testing framework to test our application. It complements unit tests, by testing the application in its globality.<br />
<br />
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.<br><br />
<br />
=Rules for Developers=<br />
<br />
QtTesting records high level events, and try to not record mouse events as mouse press, release or move.<br><br />
Furthermore, QtTesting is still under heavy development and some low level events won't be properly recorded.<br><br />
<br />
'''Please be aware of those following warning :''' <br />
<br />
* Use '''''"activated"''''' signal instead of '''''"clicked"''''', when connection Qt views<br />
<br />
=How QtTesting and CTK work=<br />
<br />
=Write a 3DSlicer test using QtTesting=<br />
<br />
QtTesting framework can also be use to create module test.<br> Use the description below, but instead of <code>Slicer/Applications/SlicerApp/Testing</code> all the path start by <code>Slicer/Path/To/The/Modules/Testing</code><br />
<br />
Following is the different step to create a test using QtTesting framework. <br />
<br />
== Create your XML script ==<br />
See [http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/SlicerApplication/QtTesting QtTesting user Wiki] to know how to create this xml script.<br><br />
'''Save the xml script to''' <code>Slicer/Applications/SlicerApp/Data/Input/MYTUTORIALNAME.xml''</code><br><br />
{{ambox <br />
| type = content<br />
|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]<br><br />
[[Documentation/{{documentation/version}}/Modules/SampleData Sample Data]] module according to the current Slicer version<br />
}}<br />
<br />
== Create a Python script ==<br />
''This Python test will start 3DSlicer and run the previously recorded xml script''<br />
<br />
'''''Create a python file with the following lines'''''<br />
<br />
import os<br />
import slicer<br />
import ApplicationsSlicerAppData as data<br />
filepath = data.input + '/MYTUTORIALNAME.xml') ex : NeurosurgicalPlanningTutorial.xml<br />
testUtility = slicer.app.testingUtility()<br />
success = testUtility.playTests(filepath)<br />
if not success :<br />
raise Exception('Failed to finished properly the play back !')<br />
<br />
'''''Save to the directory ''''' <code>Slicer/Applications/SlicerApp/Testing/Python/MYTUTORIALNAME.py </code><br />
<br />
== Add the test in CMake ==<br />
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.<br />
<br />
Edit the file <code>Slicer/Applications/SlicerApp/Testing/Python/CMakeLists.txt</code><br><br />
Add your test at the end of the Slicer_USE_QTTESTING condition and add the name in the <code>set_tests_properties</code> function :<br />
<br />
if(Slicer_USE_QTTESTING)<br />
{ <br />
...<br />
slicer_add_python_test(<br />
SCRIPT MYTUTORIALNAME.py<br />
SLICER_ARGS --launcher-no-splash --qt-testing)<br />
set_tests_properties(<br />
py_NeurosurgicalPlanningTutorial<br />
py_DiffusionTensorImagingTutorial<br />
....<br />
py_MYTUTORIALNAME<br />
...<br />
PROPERTIES RUN_SERIAL ON<br />
)<br />
}<br />
<br />
<br />
You just wrote a Slicer Unit Test using QtTesting framework !<br />
<br />
== Run your test==<br />
<br />
You can either use directly CTest or the pyhton script created.<br />
<br />
===Using CTest===<br />
{|width = "100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer-Superbuild/Slicer-build<br />
$ ctest -R MYTUTORIALNAME -VV<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer-Superbuild\Slicer-build<br />
$ path\to\cmake\ctest.exe -R MYTUTORIALNAME -VV<br />
|}<br />
<br />
===Using the python script===<br />
{|width="100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer/Application/SlicerApp/Testing/Python<br />
$ python MYTUTORIALNAME.py<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer\Applicaiton\SlicerApp\Testing\Python<br />
$ path\to\Slicer-Superbuild\python-build\PCBuild\python.exe MYTUTORIALNAME.py<br />
|}<br />
<br />
=Create custom translator/player=<br />
<br />
After created a custom widget, it might be possible that all its actions are not properly recorded, or played.<br><br />
QtTesting provides us basic translator and player template, to create our custom translator and player according to the widget. <br><br />
<br />
You can use the following command to create those basic files.<br />
<br />
{|width="100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer-Superbuild/CTK-build/QtTesting/Utilities/Scripts<br />
$ python TranslatorPlayerWizard.py MY_WIDGET_NAME<br />
$ cd ../MY_WIDGET_NAME<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer-Superbuild<br />
$ python-build\PCBuild\python.exe CTK-build\QtTesting\Utilities\Scripts\TranslatorPlayerWizard.py MY_WIDGET_NAME<br />
$ cd ../MY_WIDGET_NAME<br />
|}<br />
<br />
{{ambox<br />
| type = <br />
| text = 4 files should have been created ! <br> <br />
<code>MY_WIDGET_NAMETranslator.cpp <br> <br />
MY_WIDGET_NAMETranslator.h <br> <br />
MY_WIDGET_NAMEPlayer.cpp <br> <br />
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.<br />
}}<br />
<br />
Finally move the 4 files to the same directory as your widget<br />
<br />
$ cd path/to/Slicer-Superbuild/CTK-build/QtTesting/Utilities/MY_WIDGET_NAME<br />
$ mv MY_WIDGET_NAMETranslator.cpp MY_WIDGET_NAMETranslator.h MY_WIDGET_NAMEPlayer.cpp MY_WIDGET_NAMEPlayer.h Path/To/My/Widget/Directory<br />
<br />
or just a simple copy to the same directory as your widget<br />
<br />
$ cp MY_WIDGET_NAMETranslator.cpp MY_WIDGET_NAMETranslator.h MY_WIDGET_NAMEPlayer.cpp MY_WIDGET_NAMEPlayer.h Path/To/My/Widget/Directory<br />
<br />
=Open bugs=<br />
Work in progress, following the two bug trackers :<br />
<br />
[http://na-mic.org/Mantis/search.php?project_id=3&category=QtTesting&sticky_issues=off&sortby=last_updated&dir=DESC&hide_status_id=-2 Slicer issues]<br />
<br />
[https://github.com/commontk/CTK/issues?labels=Testing&milestone=&page=1&state=open QtTesting issues]</div>BenjaminLonghttps://www.slicer.org/w/index.php?title=Documentation/Nightly/SlicerApplication/QtTesting&diff=26627Documentation/Nightly/SlicerApplication/QtTesting2012-06-05T15:20:49Z<p>BenjaminLong: /* Player */</p>
<hr />
<div>{|width="100%"<br />
|<br />
__TOC__<br />
|align="right"|<br />
[[Image: 3DSlicerQtTesting.png]]<br />
|}<br />
=Overview=<br />
<br />
Too lazy to do the same actions over and over? QtTesting is the answer! The QtTesting library provides you with an easy way to record and play macros with 3DSlicer. Included in this library is a user-friendly recording interface that shows you what actions you're recording as well as a simple and smart playback interface that will allow you to control actions whenever you want. With no input from the user, QtTesting record all accomplished actions from the point you have started the record until you stop it! "Create a puppet and let it do the rest ... "<br />
<br />
Slicer developers use this library to record tutorials and test the 3D Slicer application. How to create you own [http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/QtTesting QtTesting test]. <br><br />
<br />
<br />
[[Image: QtTestingMenu.png]]<br />
<br />
{{ambox <br />
| text = ''QtTesting is an effort started by the [http://paraview.org/Wiki/Testing_design ParaView team]'' <br />
}}<br />
<br />
==Activate QtTesting==<br />
<br />
{|width="100%"<br />
|valign="top"|<br />
By default, QtTesting is not activated. You must enable it to be able to record or play a saved macro.<br />
* Open the [[Documentation/{{documentation/version}}/SlicerApplication/ApplicationSettings|Application Settings]] dialog.<br />
* On the left side, select the ''QtTesting'' panel<br />
* Enable QtTesting by toggling the checkbox<br />
* Restart Slicer<br />
|align="right"|<br />
[[Image: QtTestingSettigns.png |450px]]<br />
|}<br />
<br />
<br />
==Recorder==<br />
Recording a macro consists in observing all the high level events (or low level in some cases) that the user generate by interacting with the GUI elements. All the events are saved into a file (.xml) that can be used later to [[#Player|replay]] the recorded events in the same or different instance of the Slicer application.<br />
{|width="100%"<br />
|<br />
=== How to record a macro===<br />
* From the [[Documentation/{{documentation/version}}/SlicerApplication/MainApplicationGUI#Application_Menu|menu bar]], open the ''Edit'' menu and select the ''Record Macro'' item to start recording all your following events.<br />
''A record dialog appears at the bottom left of the application''<br />
<br />
=== Record dialog ===<br />
* Shows the last event recorded<br />
* Numbers of events recorded<br />
* ''You can stop the recording anytime by clicking on the Stop button''<br />
<br />
=== Save macro ===<br />
* When the recording is stopped, a dialog shows up to ask where to save the recorded macro file.<br />
<br />
|align="right"|<br />
[[Image: QtTestingRecorderDialog.jpg |300px]]<br />
|}<br />
<br />
<br />
==Player==<br />
Recorded macros (.xml) can be replayed within Slicer sessions. Note that the success of the macro execution can depend on the original state of the application.<br />
<br />
{|width="100%"<br />
|<br />
=== How to play a macro ===<br />
* From the [[Documentation/{{documentation/version}}/SlicerApplication/MainApplicationGUI#Application_Menu|menu bar]], open the ''Edit'' menu and select the ''Play Macro'' item to open the player dialog.<br />
<br />
* Choose the xml macro that you want to play<br />
<br />
* Use the player dialog to start the macro<br />
<br />
Slicer will ask you if you want to restore the previous recorded settings. See [[Documentation/{{documentation/version}}/SlicerApplication/QtTesting#Default_settings_recorded|below]]<br />
<br />
=== Player dialog ===<br />
*'''Controller widget'''<br />
** Play, pause, stop or play-step-by-step your macro.<br />
** ''Logs'' check button shows/hides information about played events and errors if any.<br />
** ''Time step'' controls the playback speed by waiting Xms before playing each event.<br />
<br />
* '''Player tab''' (''default tab'')<br />
** Show the macro file played.<br />
<br />
* '''Info tab''' :<br />
** Show the last event played.<br />
<br />
===Default settings recorded===<br />
To limit playback problems, QtTesting records automatically some of the applications settings.<br />
* General settings :<br />
** The application's geometry<br />
** The application's state<br />
** The application's name<br />
** The application's version<br />
<br />
* 3DSlicer settings :<br />
** The current layout<br />
** The current module<br />
<br />
Before each play back, the application might have different current settings, QtTesting then asks if you want to restore the settings to the record application state. To maximize the chance of a successful playback, settings must be restored to set the application into a state as much as possible similar to when the macro was recorded.<br><br />
{{ambox<br />
| type = speedy<br />
| small = left<br />
| text = It's strongly recommended to accept !<br />
}}<br />
<br />
|align="right"|<br />
[[image: QtTestintMenuPlayerback.png | 250px]]<br />
<br />
[[image: QtTestintMacroFileDialog.png | 300px]]<br />
<br />
[[image: QtTestintPlayererDialog.jpg | 300px]]<br />
<br />
[[image: QtTestintRestoreSettingsDialog.png | 300px]]<br />
|}<br />
<br />
==User limitations==<br />
<br />
''QtTesting in 3DSlicer is still under heavy development, some events might not be recorded properly.''<br />
<br />
===What is subject to not work :===<br />
* Some actions under submenus, mainly actions on widget.<br />
<br />
===Work, but not perfectly:===<br />
* Shifts/offsets might happen when you recording events in the 3D views.</div>BenjaminLonghttps://www.slicer.org/w/index.php?title=File:QtTestintMenuPlayerback.png&diff=26624File:QtTestintMenuPlayerback.png2012-06-05T15:19:12Z<p>BenjaminLong: </p>
<hr />
<div></div>BenjaminLonghttps://www.slicer.org/w/index.php?title=Documentation/Nightly/SlicerApplication/QtTesting&diff=26623Documentation/Nightly/SlicerApplication/QtTesting2012-06-05T15:18:58Z<p>BenjaminLong: /* Player */</p>
<hr />
<div>{|width="100%"<br />
|<br />
__TOC__<br />
|align="right"|<br />
[[Image: 3DSlicerQtTesting.png]]<br />
|}<br />
=Overview=<br />
<br />
Too lazy to do the same actions over and over? QtTesting is the answer! The QtTesting library provides you with an easy way to record and play macros with 3DSlicer. Included in this library is a user-friendly recording interface that shows you what actions you're recording as well as a simple and smart playback interface that will allow you to control actions whenever you want. With no input from the user, QtTesting record all accomplished actions from the point you have started the record until you stop it! "Create a puppet and let it do the rest ... "<br />
<br />
Slicer developers use this library to record tutorials and test the 3D Slicer application. How to create you own [http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/QtTesting QtTesting test]. <br><br />
<br />
<br />
[[Image: QtTestingMenu.png]]<br />
<br />
{{ambox <br />
| text = ''QtTesting is an effort started by the [http://paraview.org/Wiki/Testing_design ParaView team]'' <br />
}}<br />
<br />
==Activate QtTesting==<br />
<br />
{|width="100%"<br />
|valign="top"|<br />
By default, QtTesting is not activated. You must enable it to be able to record or play a saved macro.<br />
* Open the [[Documentation/{{documentation/version}}/SlicerApplication/ApplicationSettings|Application Settings]] dialog.<br />
* On the left side, select the ''QtTesting'' panel<br />
* Enable QtTesting by toggling the checkbox<br />
* Restart Slicer<br />
|align="right"|<br />
[[Image: QtTestingSettigns.png |450px]]<br />
|}<br />
<br />
<br />
==Recorder==<br />
Recording a macro consists in observing all the high level events (or low level in some cases) that the user generate by interacting with the GUI elements. All the events are saved into a file (.xml) that can be used later to [[#Player|replay]] the recorded events in the same or different instance of the Slicer application.<br />
{|width="100%"<br />
|<br />
=== How to record a macro===<br />
* From the [[Documentation/{{documentation/version}}/SlicerApplication/MainApplicationGUI#Application_Menu|menu bar]], open the ''Edit'' menu and select the ''Record Macro'' item to start recording all your following events.<br />
''A record dialog appears at the bottom left of the application''<br />
<br />
=== Record dialog ===<br />
* Shows the last event recorded<br />
* Numbers of events recorded<br />
* ''You can stop the recording anytime by clicking on the Stop button''<br />
<br />
=== Save macro ===<br />
* When the recording is stopped, a dialog shows up to ask where to save the recorded macro file.<br />
<br />
|align="right"|<br />
[[Image: QtTestingRecorderDialog.jpg |300px]]<br />
|}<br />
<br />
<br />
==Player==<br />
Recorded macros (.xml) can be replayed within Slicer sessions. Note that the success of the macro execution can depend on the original state of the application.<br />
<br />
{|width="100%"<br />
|<br />
=== How to play a macro ===<br />
* From the [[Documentation/{{documentation/version}}/SlicerApplication/MainApplicationGUI#Application_Menu|menu bar]], open the ''Edit'' menu and select the ''Play Macro'' item to open the player dialog.<br />
<br />
* Choose the xml macro that you want to play<br />
<br />
* Use the player dialog to start the macro<br />
<br />
Slicer will ask you if you want to restore the previous recorded settings. See [[Documentation/{{documentation/version}}/SlicerApplication/QtTesting#Default_settings_recorded|below]]<br />
<br />
=== Player dialog ===<br />
*'''Controller widget'''<br />
** Play, pause, stop or play-step-by-step your macro.<br />
** ''Logs'' check button shows/hides information about played events and errors if any.<br />
** ''Time step'' controls the playback speed by waiting Xms before playing each event.<br />
<br />
* '''Player tab''' (''default tab'')<br />
** Show the macro file played.<br />
<br />
* '''Info tab''' :<br />
** Show the last event played.<br />
<br />
===Default settings recorded===<br />
To limit playback problems, QtTesting records automatically some of the applications settings.<br />
* General settings :<br />
** The application's geometry<br />
** The application's state<br />
** The application's name<br />
** The application's version<br />
<br />
* 3DSlicer settings :<br />
** The current layout<br />
** The current module<br />
<br />
Before each play back, the application might have different current settings, QtTesting then asks if you want to restore the settings to the record application state. To maximize the chance of a successful playback, settings must be restored to set the application into a state as much as possible similar to when the macro was recorded.<br><br />
{{ambox<br />
| type = speedy<br />
| small = left<br />
| text = It's strongly recommended to accept !<br />
}}<br />
<br />
|align="right"|<br />
[[image: QtTestintMenuPlayerback.png | 300px]]<br />
<br />
[[image: QtTestintMacroFileDialog.png | 300px]]<br />
<br />
[[image: QtTestintPlayererDialog.jpg | 300px]]<br />
<br />
[[image: QtTestintRestoreSettingsDialog.png | 300px]]<br />
|}<br />
<br />
==User limitations==<br />
<br />
''QtTesting in 3DSlicer is still under heavy development, some events might not be recorded properly.''<br />
<br />
===What is subject to not work :===<br />
* Some actions under submenus, mainly actions on widget.<br />
<br />
===Work, but not perfectly:===<br />
* Shifts/offsets might happen when you recording events in the 3D views.</div>BenjaminLonghttps://www.slicer.org/w/index.php?title=File:QtTestintMacroFileDialog.png&diff=26621File:QtTestintMacroFileDialog.png2012-06-05T15:13:35Z<p>BenjaminLong: </p>
<hr />
<div></div>BenjaminLonghttps://www.slicer.org/w/index.php?title=Documentation/Nightly/SlicerApplication/QtTesting&diff=26620Documentation/Nightly/SlicerApplication/QtTesting2012-06-05T15:12:40Z<p>BenjaminLong: /* Player */</p>
<hr />
<div>{|width="100%"<br />
|<br />
__TOC__<br />
|align="right"|<br />
[[Image: 3DSlicerQtTesting.png]]<br />
|}<br />
=Overview=<br />
<br />
Too lazy to do the same actions over and over? QtTesting is the answer! The QtTesting library provides you with an easy way to record and play macros with 3DSlicer. Included in this library is a user-friendly recording interface that shows you what actions you're recording as well as a simple and smart playback interface that will allow you to control actions whenever you want. With no input from the user, QtTesting record all accomplished actions from the point you have started the record until you stop it! "Create a puppet and let it do the rest ... "<br />
<br />
Slicer developers use this library to record tutorials and test the 3D Slicer application. How to create you own [http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/QtTesting QtTesting test]. <br><br />
<br />
<br />
[[Image: QtTestingMenu.png]]<br />
<br />
{{ambox <br />
| text = ''QtTesting is an effort started by the [http://paraview.org/Wiki/Testing_design ParaView team]'' <br />
}}<br />
<br />
==Activate QtTesting==<br />
<br />
{|width="100%"<br />
|valign="top"|<br />
By default, QtTesting is not activated. You must enable it to be able to record or play a saved macro.<br />
* Open the [[Documentation/{{documentation/version}}/SlicerApplication/ApplicationSettings|Application Settings]] dialog.<br />
* On the left side, select the ''QtTesting'' panel<br />
* Enable QtTesting by toggling the checkbox<br />
* Restart Slicer<br />
|align="right"|<br />
[[Image: QtTestingSettigns.png |450px]]<br />
|}<br />
<br />
<br />
==Recorder==<br />
Recording a macro consists in observing all the high level events (or low level in some cases) that the user generate by interacting with the GUI elements. All the events are saved into a file (.xml) that can be used later to [[#Player|replay]] the recorded events in the same or different instance of the Slicer application.<br />
{|width="100%"<br />
|<br />
=== How to record a macro===<br />
* From the [[Documentation/{{documentation/version}}/SlicerApplication/MainApplicationGUI#Application_Menu|menu bar]], open the ''Edit'' menu and select the ''Record Macro'' item to start recording all your following events.<br />
''A record dialog appears at the bottom left of the application''<br />
<br />
=== Record dialog ===<br />
* Shows the last event recorded<br />
* Numbers of events recorded<br />
* ''You can stop the recording anytime by clicking on the Stop button''<br />
<br />
=== Save macro ===<br />
* When the recording is stopped, a dialog shows up to ask where to save the recorded macro file.<br />
<br />
|align="right"|<br />
[[Image: QtTestingRecorderDialog.jpg |300px]]<br />
|}<br />
<br />
<br />
==Player==<br />
Recorded macros (.xml) can be replayed within Slicer sessions. Note that the success of the macro execution can depend on the original state of the application.<br />
<br />
{|width="100%"<br />
|<br />
=== How to play a macro ===<br />
* From the [[Documentation/{{documentation/version}}/SlicerApplication/MainApplicationGUI#Application_Menu|menu bar]], open the ''Edit'' menu and select the ''Play Macro'' item to open the player dialog.<br />
<br />
* Choose the xml macro that you want to play<br />
<br />
* Use the player dialog to start the macro<br />
<br />
Slicer will ask you if you want to restore the previous recorded settings. See [[Documentation/{{documentation/version}}/SlicerApplication/QtTesting#Default_settings_recorded|below]]<br />
<br />
=== Player dialog ===<br />
*'''Controller widget'''<br />
** Play, pause, stop or play-step-by-step your macro.<br />
** ''Logs'' check button shows/hides information about played events and errors if any.<br />
** ''Time step'' controls the playback speed by waiting Xms before playing each event.<br />
<br />
* '''Player tab''' (''default tab'')<br />
** Show the macro file played.<br />
<br />
* '''Info tab''' :<br />
** Show the last event played.<br />
<br />
===Default settings recorded===<br />
To limit playback problems, QtTesting records automatically some of the applications settings.<br />
* General settings :<br />
** The application's geometry<br />
** The application's state<br />
** The application's name<br />
** The application's version<br />
<br />
* 3DSlicer settings :<br />
** The current layout<br />
** The current module<br />
<br />
Before each play back, the application might have different current settings, QtTesting then asks if you want to restore the settings to the record application state. To maximize the chance of a successful playback, settings must be restored to set the application into a state as much as possible similar to when the macro was recorded.<br><br />
{{ambox<br />
| type = speedy<br />
| small = left<br />
| text = It's strongly recommended to accept !<br />
}}<br />
<br />
|align="right"|<br />
[[image: QtTestintMacroFileDialog.png | 300px]]<br />
<br />
[[image: QtTestintPlayererDialog.jpg | 300px]]<br />
<br />
[[image: QtTestintRestoreSettingsDialog.png | 300px]]<br />
|}<br />
<br />
==User limitations==<br />
<br />
''QtTesting in 3DSlicer is still under heavy development, some events might not be recorded properly.''<br />
<br />
===What is subject to not work :===<br />
* Some actions under submenus, mainly actions on widget.<br />
<br />
===Work, but not perfectly:===<br />
* Shifts/offsets might happen when you recording events in the 3D views.</div>BenjaminLonghttps://www.slicer.org/w/index.php?title=Documentation/Nightly/SlicerApplication/QtTesting&diff=26619Documentation/Nightly/SlicerApplication/QtTesting2012-06-05T15:12:19Z<p>BenjaminLong: /* Player */</p>
<hr />
<div>{|width="100%"<br />
|<br />
__TOC__<br />
|align="right"|<br />
[[Image: 3DSlicerQtTesting.png]]<br />
|}<br />
=Overview=<br />
<br />
Too lazy to do the same actions over and over? QtTesting is the answer! The QtTesting library provides you with an easy way to record and play macros with 3DSlicer. Included in this library is a user-friendly recording interface that shows you what actions you're recording as well as a simple and smart playback interface that will allow you to control actions whenever you want. With no input from the user, QtTesting record all accomplished actions from the point you have started the record until you stop it! "Create a puppet and let it do the rest ... "<br />
<br />
Slicer developers use this library to record tutorials and test the 3D Slicer application. How to create you own [http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/QtTesting QtTesting test]. <br><br />
<br />
<br />
[[Image: QtTestingMenu.png]]<br />
<br />
{{ambox <br />
| text = ''QtTesting is an effort started by the [http://paraview.org/Wiki/Testing_design ParaView team]'' <br />
}}<br />
<br />
==Activate QtTesting==<br />
<br />
{|width="100%"<br />
|valign="top"|<br />
By default, QtTesting is not activated. You must enable it to be able to record or play a saved macro.<br />
* Open the [[Documentation/{{documentation/version}}/SlicerApplication/ApplicationSettings|Application Settings]] dialog.<br />
* On the left side, select the ''QtTesting'' panel<br />
* Enable QtTesting by toggling the checkbox<br />
* Restart Slicer<br />
|align="right"|<br />
[[Image: QtTestingSettigns.png |450px]]<br />
|}<br />
<br />
<br />
==Recorder==<br />
Recording a macro consists in observing all the high level events (or low level in some cases) that the user generate by interacting with the GUI elements. All the events are saved into a file (.xml) that can be used later to [[#Player|replay]] the recorded events in the same or different instance of the Slicer application.<br />
{|width="100%"<br />
|<br />
=== How to record a macro===<br />
* From the [[Documentation/{{documentation/version}}/SlicerApplication/MainApplicationGUI#Application_Menu|menu bar]], open the ''Edit'' menu and select the ''Record Macro'' item to start recording all your following events.<br />
''A record dialog appears at the bottom left of the application''<br />
<br />
=== Record dialog ===<br />
* Shows the last event recorded<br />
* Numbers of events recorded<br />
* ''You can stop the recording anytime by clicking on the Stop button''<br />
<br />
=== Save macro ===<br />
* When the recording is stopped, a dialog shows up to ask where to save the recorded macro file.<br />
<br />
|align="right"|<br />
[[Image: QtTestingRecorderDialog.jpg |300px]]<br />
|}<br />
<br />
<br />
==Player==<br />
Recorded macros (.xml) can be replayed within Slicer sessions. Note that the success of the macro execution can depend on the original state of the application.<br />
<br />
{|width="100%"<br />
|<br />
=== How to play a macro ===<br />
* From the [[Documentation/{{documentation/version}}/SlicerApplication/MainApplicationGUI#Application_Menu|menu bar]], open the ''Edit'' menu and select the ''Play Macro'' item to open the player dialog.<br />
<br />
* Choose the xml macro that you want to play<br />
<br />
* Use the player dialog to start the macro<br />
<br />
Slicer will ask you if you want to restore the previous recorded settings. See [[Documentation/{{documentation/version}}/SlicerApplication/QtTesting#Default_settings_recorded|below]]<br />
<br />
=== Player dialog ===<br />
*'''Controller widget'''<br />
** Play, pause, stop or play-step-by-step your macro.<br />
** ''Logs'' check button shows/hides information about played events and errors if any.<br />
** ''Time step'' controls the playback speed by waiting Xms before playing each event.<br />
<br />
* '''Player tab''' (''default tab'')<br />
** Show the macro file played.<br />
<br />
* '''Info tab''' :<br />
** Show the last event played.<br />
<br />
===Default settings recorded===<br />
To limit playback problems, QtTesting records automatically some of the applications settings.<br />
* General settings :<br />
** The application's geometry<br />
** The application's state<br />
** The application's name<br />
** The application's version<br />
<br />
* 3DSlicer settings :<br />
** The current layout<br />
** The current module<br />
<br />
Before each play back, the application might have different current settings, QtTesting then asks if you want to restore the settings to the record application state. To maximize the chance of a successful playback, settings must be restored to set the application into a state as much as possible similar to when the macro was recorded.<br><br />
{{ambox<br />
| type = speedy<br />
| small = left<br />
| text = It's strongly recommended to accept !<br />
}}<br />
<br />
|align="right"|<br />
[[image: QtTestintMacroFileDialog.jpg | 300px]]<br />
<br />
[[image: QtTestintPlayererDialog.jpg | 300px]]<br />
<br />
[[image: QtTestintRestoreSettingsDialog.png | 300px]]<br />
|}<br />
<br />
==User limitations==<br />
<br />
''QtTesting in 3DSlicer is still under heavy development, some events might not be recorded properly.''<br />
<br />
===What is subject to not work :===<br />
* Some actions under submenus, mainly actions on widget.<br />
<br />
===Work, but not perfectly:===<br />
* Shifts/offsets might happen when you recording events in the 3D views.</div>BenjaminLonghttps://www.slicer.org/w/index.php?title=File:QtTestintMacroFileDialog.jpg&diff=26618File:QtTestintMacroFileDialog.jpg2012-06-05T15:10:11Z<p>BenjaminLong: </p>
<hr />
<div></div>BenjaminLonghttps://www.slicer.org/w/index.php?title=Documentation/Nightly/SlicerApplication/QtTesting&diff=26617Documentation/Nightly/SlicerApplication/QtTesting2012-06-05T15:09:56Z<p>BenjaminLong: /* Player */</p>
<hr />
<div>{|width="100%"<br />
|<br />
__TOC__<br />
|align="right"|<br />
[[Image: 3DSlicerQtTesting.png]]<br />
|}<br />
=Overview=<br />
<br />
Too lazy to do the same actions over and over? QtTesting is the answer! The QtTesting library provides you with an easy way to record and play macros with 3DSlicer. Included in this library is a user-friendly recording interface that shows you what actions you're recording as well as a simple and smart playback interface that will allow you to control actions whenever you want. With no input from the user, QtTesting record all accomplished actions from the point you have started the record until you stop it! "Create a puppet and let it do the rest ... "<br />
<br />
Slicer developers use this library to record tutorials and test the 3D Slicer application. How to create you own [http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/QtTesting QtTesting test]. <br><br />
<br />
<br />
[[Image: QtTestingMenu.png]]<br />
<br />
{{ambox <br />
| text = ''QtTesting is an effort started by the [http://paraview.org/Wiki/Testing_design ParaView team]'' <br />
}}<br />
<br />
==Activate QtTesting==<br />
<br />
{|width="100%"<br />
|valign="top"|<br />
By default, QtTesting is not activated. You must enable it to be able to record or play a saved macro.<br />
* Open the [[Documentation/{{documentation/version}}/SlicerApplication/ApplicationSettings|Application Settings]] dialog.<br />
* On the left side, select the ''QtTesting'' panel<br />
* Enable QtTesting by toggling the checkbox<br />
* Restart Slicer<br />
|align="right"|<br />
[[Image: QtTestingSettigns.png |450px]]<br />
|}<br />
<br />
<br />
==Recorder==<br />
Recording a macro consists in observing all the high level events (or low level in some cases) that the user generate by interacting with the GUI elements. All the events are saved into a file (.xml) that can be used later to [[#Player|replay]] the recorded events in the same or different instance of the Slicer application.<br />
{|width="100%"<br />
|<br />
=== How to record a macro===<br />
* From the [[Documentation/{{documentation/version}}/SlicerApplication/MainApplicationGUI#Application_Menu|menu bar]], open the ''Edit'' menu and select the ''Record Macro'' item to start recording all your following events.<br />
''A record dialog appears at the bottom left of the application''<br />
<br />
=== Record dialog ===<br />
* Shows the last event recorded<br />
* Numbers of events recorded<br />
* ''You can stop the recording anytime by clicking on the Stop button''<br />
<br />
=== Save macro ===<br />
* When the recording is stopped, a dialog shows up to ask where to save the recorded macro file.<br />
<br />
|align="right"|<br />
[[Image: QtTestingRecorderDialog.jpg |300px]]<br />
|}<br />
<br />
<br />
==Player==<br />
Recorded macros (.xml) can be replayed within Slicer sessions. Note that the success of the macro execution can depend on the original state of the application.<br />
<br />
{|width="100%"<br />
|<br />
=== How to play a macro ===<br />
* From the [[Documentation/{{documentation/version}}/SlicerApplication/MainApplicationGUI#Application_Menu|menu bar]], open the ''Edit'' menu and select the ''Play Macro'' item to open the player dialog.<br />
<br />
* Choose the xml macro that you want to play<br />
<br />
* Use the player dialog to start the macro<br />
<br />
Slicer will ask you if you want to restore the previous recorded settings. See [[Documentation/{{documentation/version}}/SlicerApplication/QtTesting#Default_settings_recorded|below]]<br />
<br />
=== Player dialog ===<br />
*'''Controller widget'''<br />
** Play, pause, stop or play-step-by-step your macro.<br />
** ''Logs'' check button shows/hides information about played events and errors if any.<br />
** ''Time step'' controls the playback speed by waiting Xms before playing each event.<br />
<br />
* '''Player tab''' (''default tab'')<br />
** Show the macro file played.<br />
<br />
* '''Info tab''' :<br />
** Show the last event played.<br />
<br />
===Default settings recorded===<br />
To limit playback problems, QtTesting records automatically some of the applications settings.<br />
* General settings :<br />
** The application's geometry<br />
** The application's state<br />
** The application's name<br />
** The application's version<br />
<br />
* 3DSlicer settings :<br />
** The current layout<br />
** The current module<br />
<br />
Before each play back, the application might have different current settings, QtTesting then asks if you want to restore the settings to the record application state. To maximize the chance of a successful playback, settings must be restored to set the application into a state as much as possible similar to when the macro was recorded.<br><br />
{{ambox<br />
| type = speedy<br />
| small = left<br />
| text = It's strongly recommended to accept !<br />
}}<br />
<br />
|align="right"|<br />
[[image: QtTestintMacroFileDialog.jpg | 300px]]<br />
[[image: QtTestintPlayererDialog.jpg | 300px]]<br />
[[image: QtTestintRestoreSettingsDialog.png | 300px]]<br />
|}<br />
<br />
==User limitations==<br />
<br />
''QtTesting in 3DSlicer is still under heavy development, some events might not be recorded properly.''<br />
<br />
===What is subject to not work :===<br />
* Some actions under submenus, mainly actions on widget.<br />
<br />
===Work, but not perfectly:===<br />
* Shifts/offsets might happen when you recording events in the 3D views.</div>BenjaminLonghttps://www.slicer.org/w/index.php?title=Documentation/Nightly/SlicerApplication/QtTesting&diff=26616Documentation/Nightly/SlicerApplication/QtTesting2012-06-05T15:03:38Z<p>BenjaminLong: /* How to play a macro */</p>
<hr />
<div>{|width="100%"<br />
|<br />
__TOC__<br />
|align="right"|<br />
[[Image: 3DSlicerQtTesting.png]]<br />
|}<br />
=Overview=<br />
<br />
Too lazy to do the same actions over and over? QtTesting is the answer! The QtTesting library provides you with an easy way to record and play macros with 3DSlicer. Included in this library is a user-friendly recording interface that shows you what actions you're recording as well as a simple and smart playback interface that will allow you to control actions whenever you want. With no input from the user, QtTesting record all accomplished actions from the point you have started the record until you stop it! "Create a puppet and let it do the rest ... "<br />
<br />
Slicer developers use this library to record tutorials and test the 3D Slicer application. How to create you own [http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/QtTesting QtTesting test]. <br><br />
<br />
<br />
[[Image: QtTestingMenu.png]]<br />
<br />
{{ambox <br />
| text = ''QtTesting is an effort started by the [http://paraview.org/Wiki/Testing_design ParaView team]'' <br />
}}<br />
<br />
==Activate QtTesting==<br />
<br />
{|width="100%"<br />
|valign="top"|<br />
By default, QtTesting is not activated. You must enable it to be able to record or play a saved macro.<br />
* Open the [[Documentation/{{documentation/version}}/SlicerApplication/ApplicationSettings|Application Settings]] dialog.<br />
* On the left side, select the ''QtTesting'' panel<br />
* Enable QtTesting by toggling the checkbox<br />
* Restart Slicer<br />
|align="right"|<br />
[[Image: QtTestingSettigns.png |450px]]<br />
|}<br />
<br />
<br />
==Recorder==<br />
Recording a macro consists in observing all the high level events (or low level in some cases) that the user generate by interacting with the GUI elements. All the events are saved into a file (.xml) that can be used later to [[#Player|replay]] the recorded events in the same or different instance of the Slicer application.<br />
{|width="100%"<br />
|<br />
=== How to record a macro===<br />
* From the [[Documentation/{{documentation/version}}/SlicerApplication/MainApplicationGUI#Application_Menu|menu bar]], open the ''Edit'' menu and select the ''Record Macro'' item to start recording all your following events.<br />
''A record dialog appears at the bottom left of the application''<br />
<br />
=== Record dialog ===<br />
* Shows the last event recorded<br />
* Numbers of events recorded<br />
* ''You can stop the recording anytime by clicking on the Stop button''<br />
<br />
=== Save macro ===<br />
* When the recording is stopped, a dialog shows up to ask where to save the recorded macro file.<br />
<br />
|align="right"|<br />
[[Image: QtTestingRecorderDialog.jpg |300px]]<br />
|}<br />
<br />
<br />
==Player==<br />
Recorded macros (.xml) can be replayed within Slicer sessions. Note that the success of the macro execution can depend on the original state of the application.<br />
<br />
{|width="100%"<br />
|<br />
=== How to play a macro ===<br />
* From the [[Documentation/{{documentation/version}}/SlicerApplication/MainApplicationGUI#Application_Menu|menu bar]], open the ''Edit'' menu and select the ''Play Macro'' item to open the player dialog.<br />
<br />
* Choose the xml macro that you want to play<br />
<br />
* Use the player dialog to start the macro<br />
<br />
Slicer will ask you if you want to restore the previous recorded settings. See [[Documentation/{{documentation/version}}/SlicerApplication/QtTesting#Default_settings_recorded|below]]<br />
<br />
=== Player dialog ===<br />
*'''Controller widget'''<br />
** Play, pause, stop or play-step-by-step your macro.<br />
** ''Logs'' check button shows/hides information about played events and errors if any.<br />
** ''Time step'' controls the playback speed by waiting Xms before playing each event.<br />
<br />
* '''Player tab''' (''default tab'')<br />
** Show the macro file played.<br />
<br />
* '''Info tab''' :<br />
** Show the last event played.<br />
<br />
===Default settings recorded===<br />
To limit playback problems, QtTesting records automatically some of the applications settings.<br />
* General settings :<br />
** The application's geometry<br />
** The application's state<br />
** The application's name<br />
** The application's version<br />
<br />
* 3DSlicer settings :<br />
** The current layout<br />
** The current module<br />
<br />
Before each play back, the application might have different current settings, QtTesting then asks if you want to restore the settings to the record application state. To maximize the chance of a successful playback, settings must be restored to set the application into a state as much as possible similar to when the macro was recorded.<br><br />
{{ambox<br />
| type = speedy<br />
| small = left<br />
| text = It's strongly recommended to accept !<br />
}}<br />
<br />
|align="right"|<br />
[[image: QtTestintPlayererDialog.jpg | 300px]]<br />
[[image: QtTestintRestoreSettingsDialog.png | 300px]]<br />
|}<br />
<br />
<br />
==User limitations==<br />
<br />
''QtTesting in 3DSlicer is still under heavy development, some events might not be recorded properly.''<br />
<br />
===What is subject to not work :===<br />
* Some actions under submenus, mainly actions on widget.<br />
<br />
===Work, but not perfectly:===<br />
* Shifts/offsets might happen when you recording events in the 3D views.</div>BenjaminLonghttps://www.slicer.org/w/index.php?title=Documentation/Nightly/SlicerApplication/QtTesting&diff=26615Documentation/Nightly/SlicerApplication/QtTesting2012-06-05T15:02:02Z<p>BenjaminLong: /* How to play a macro */</p>
<hr />
<div>{|width="100%"<br />
|<br />
__TOC__<br />
|align="right"|<br />
[[Image: 3DSlicerQtTesting.png]]<br />
|}<br />
=Overview=<br />
<br />
Too lazy to do the same actions over and over? QtTesting is the answer! The QtTesting library provides you with an easy way to record and play macros with 3DSlicer. Included in this library is a user-friendly recording interface that shows you what actions you're recording as well as a simple and smart playback interface that will allow you to control actions whenever you want. With no input from the user, QtTesting record all accomplished actions from the point you have started the record until you stop it! "Create a puppet and let it do the rest ... "<br />
<br />
Slicer developers use this library to record tutorials and test the 3D Slicer application. How to create you own [http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/QtTesting QtTesting test]. <br><br />
<br />
<br />
[[Image: QtTestingMenu.png]]<br />
<br />
{{ambox <br />
| text = ''QtTesting is an effort started by the [http://paraview.org/Wiki/Testing_design ParaView team]'' <br />
}}<br />
<br />
==Activate QtTesting==<br />
<br />
{|width="100%"<br />
|valign="top"|<br />
By default, QtTesting is not activated. You must enable it to be able to record or play a saved macro.<br />
* Open the [[Documentation/{{documentation/version}}/SlicerApplication/ApplicationSettings|Application Settings]] dialog.<br />
* On the left side, select the ''QtTesting'' panel<br />
* Enable QtTesting by toggling the checkbox<br />
* Restart Slicer<br />
|align="right"|<br />
[[Image: QtTestingSettigns.png |450px]]<br />
|}<br />
<br />
<br />
==Recorder==<br />
Recording a macro consists in observing all the high level events (or low level in some cases) that the user generate by interacting with the GUI elements. All the events are saved into a file (.xml) that can be used later to [[#Player|replay]] the recorded events in the same or different instance of the Slicer application.<br />
{|width="100%"<br />
|<br />
=== How to record a macro===<br />
* From the [[Documentation/{{documentation/version}}/SlicerApplication/MainApplicationGUI#Application_Menu|menu bar]], open the ''Edit'' menu and select the ''Record Macro'' item to start recording all your following events.<br />
''A record dialog appears at the bottom left of the application''<br />
<br />
=== Record dialog ===<br />
* Shows the last event recorded<br />
* Numbers of events recorded<br />
* ''You can stop the recording anytime by clicking on the Stop button''<br />
<br />
=== Save macro ===<br />
* When the recording is stopped, a dialog shows up to ask where to save the recorded macro file.<br />
<br />
|align="right"|<br />
[[Image: QtTestingRecorderDialog.jpg |300px]]<br />
|}<br />
<br />
<br />
==Player==<br />
Recorded macros (.xml) can be replayed within Slicer sessions. Note that the success of the macro execution can depend on the original state of the application.<br />
<br />
{|width="100%"<br />
|<br />
=== How to play a macro ===<br />
* From the [[Documentation/{{documentation/version}}/SlicerApplication/MainApplicationGUI#Application_Menu|menu bar]], open the ''Edit'' menu and select the ''Play Macro'' item to open the player dialog.<br />
<br />
* Choose the xml macro that you want to play<br />
<br />
* Use the player dialog to start the macro<br />
<br />
Slicer will ask you if you want to restore the previous recorded settings. See [[Documentation/{{documentation/version}}/SlicerApplication/QtTesting#Default_settings_recorded below]<br />
<br />
=== Player dialog ===<br />
*'''Controller widget'''<br />
** Play, pause, stop or play-step-by-step your macro.<br />
** ''Logs'' check button shows/hides information about played events and errors if any.<br />
** ''Time step'' controls the playback speed by waiting Xms before playing each event.<br />
<br />
* '''Player tab''' (''default tab'')<br />
** Show the macro file played.<br />
<br />
* '''Info tab''' :<br />
** Show the last event played.<br />
<br />
===Default settings recorded===<br />
To limit playback problems, QtTesting records automatically some of the applications settings.<br />
* General settings :<br />
** The application's geometry<br />
** The application's state<br />
** The application's name<br />
** The application's version<br />
<br />
* 3DSlicer settings :<br />
** The current layout<br />
** The current module<br />
<br />
Before each play back, the application might have different current settings, QtTesting then asks if you want to restore the settings to the record application state. To maximize the chance of a successful playback, settings must be restored to set the application into a state as much as possible similar to when the macro was recorded.<br><br />
{{ambox<br />
| type = speedy<br />
| small = left<br />
| text = It's strongly recommended to accept !<br />
}}<br />
<br />
|align="right"|<br />
[[image: QtTestintPlayererDialog.jpg | 300px]]<br />
[[image: QtTestintRestoreSettingsDialog.png | 300px]]<br />
|}<br />
<br />
<br />
==User limitations==<br />
<br />
''QtTesting in 3DSlicer is still under heavy development, some events might not be recorded properly.''<br />
<br />
===What is subject to not work :===<br />
* Some actions under submenus, mainly actions on widget.<br />
<br />
===Work, but not perfectly:===<br />
* Shifts/offsets might happen when you recording events in the 3D views.</div>BenjaminLonghttps://www.slicer.org/w/index.php?title=Documentation/Nightly/SlicerApplication/QtTesting&diff=26614Documentation/Nightly/SlicerApplication/QtTesting2012-06-05T15:01:22Z<p>BenjaminLong: /* How to play a macro */</p>
<hr />
<div>{|width="100%"<br />
|<br />
__TOC__<br />
|align="right"|<br />
[[Image: 3DSlicerQtTesting.png]]<br />
|}<br />
=Overview=<br />
<br />
Too lazy to do the same actions over and over? QtTesting is the answer! The QtTesting library provides you with an easy way to record and play macros with 3DSlicer. Included in this library is a user-friendly recording interface that shows you what actions you're recording as well as a simple and smart playback interface that will allow you to control actions whenever you want. With no input from the user, QtTesting record all accomplished actions from the point you have started the record until you stop it! "Create a puppet and let it do the rest ... "<br />
<br />
Slicer developers use this library to record tutorials and test the 3D Slicer application. How to create you own [http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/QtTesting QtTesting test]. <br><br />
<br />
<br />
[[Image: QtTestingMenu.png]]<br />
<br />
{{ambox <br />
| text = ''QtTesting is an effort started by the [http://paraview.org/Wiki/Testing_design ParaView team]'' <br />
}}<br />
<br />
==Activate QtTesting==<br />
<br />
{|width="100%"<br />
|valign="top"|<br />
By default, QtTesting is not activated. You must enable it to be able to record or play a saved macro.<br />
* Open the [[Documentation/{{documentation/version}}/SlicerApplication/ApplicationSettings|Application Settings]] dialog.<br />
* On the left side, select the ''QtTesting'' panel<br />
* Enable QtTesting by toggling the checkbox<br />
* Restart Slicer<br />
|align="right"|<br />
[[Image: QtTestingSettigns.png |450px]]<br />
|}<br />
<br />
<br />
==Recorder==<br />
Recording a macro consists in observing all the high level events (or low level in some cases) that the user generate by interacting with the GUI elements. All the events are saved into a file (.xml) that can be used later to [[#Player|replay]] the recorded events in the same or different instance of the Slicer application.<br />
{|width="100%"<br />
|<br />
=== How to record a macro===<br />
* From the [[Documentation/{{documentation/version}}/SlicerApplication/MainApplicationGUI#Application_Menu|menu bar]], open the ''Edit'' menu and select the ''Record Macro'' item to start recording all your following events.<br />
''A record dialog appears at the bottom left of the application''<br />
<br />
=== Record dialog ===<br />
* Shows the last event recorded<br />
* Numbers of events recorded<br />
* ''You can stop the recording anytime by clicking on the Stop button''<br />
<br />
=== Save macro ===<br />
* When the recording is stopped, a dialog shows up to ask where to save the recorded macro file.<br />
<br />
|align="right"|<br />
[[Image: QtTestingRecorderDialog.jpg |300px]]<br />
|}<br />
<br />
<br />
==Player==<br />
Recorded macros (.xml) can be replayed within Slicer sessions. Note that the success of the macro execution can depend on the original state of the application.<br />
<br />
{|width="100%"<br />
|<br />
=== How to play a macro ===<br />
* From the [[Documentation/{{documentation/version}}/SlicerApplication/MainApplicationGUI#Application_Menu|menu bar]], open the ''Edit'' menu and select the ''Play Macro'' item to open the player dialog.<br />
<br />
* Choose the xml macro that you want to play<br />
<br />
* Use the player dialog to start the macro<br />
<br />
Slicer will ask you if you want to restore the previous recorded settings. See [ below]<br />
<br />
=== Player dialog ===<br />
*'''Controller widget'''<br />
** Play, pause, stop or play-step-by-step your macro.<br />
** ''Logs'' check button shows/hides information about played events and errors if any.<br />
** ''Time step'' controls the playback speed by waiting Xms before playing each event.<br />
<br />
* '''Player tab''' (''default tab'')<br />
** Show the macro file played.<br />
<br />
* '''Info tab''' :<br />
** Show the last event played.<br />
<br />
===Default settings recorded===<br />
To limit playback problems, QtTesting records automatically some of the applications settings.<br />
* General settings :<br />
** The application's geometry<br />
** The application's state<br />
** The application's name<br />
** The application's version<br />
<br />
* 3DSlicer settings :<br />
** The current layout<br />
** The current module<br />
<br />
Before each play back, the application might have different current settings, QtTesting then asks if you want to restore the settings to the record application state. To maximize the chance of a successful playback, settings must be restored to set the application into a state as much as possible similar to when the macro was recorded.<br><br />
{{ambox<br />
| type = speedy<br />
| small = left<br />
| text = It's strongly recommended to accept !<br />
}}<br />
<br />
|align="right"|<br />
[[image: QtTestintPlayererDialog.jpg | 300px]]<br />
[[image: QtTestintRestoreSettingsDialog.png | 300px]]<br />
|}<br />
<br />
<br />
==User limitations==<br />
<br />
''QtTesting in 3DSlicer is still under heavy development, some events might not be recorded properly.''<br />
<br />
===What is subject to not work :===<br />
* Some actions under submenus, mainly actions on widget.<br />
<br />
===Work, but not perfectly:===<br />
* Shifts/offsets might happen when you recording events in the 3D views.</div>BenjaminLonghttps://www.slicer.org/w/index.php?title=Documentation/Nightly/SlicerApplication/QtTesting&diff=26613Documentation/Nightly/SlicerApplication/QtTesting2012-06-05T15:00:19Z<p>BenjaminLong: /* How to play a macro */</p>
<hr />
<div>{|width="100%"<br />
|<br />
__TOC__<br />
|align="right"|<br />
[[Image: 3DSlicerQtTesting.png]]<br />
|}<br />
=Overview=<br />
<br />
Too lazy to do the same actions over and over? QtTesting is the answer! The QtTesting library provides you with an easy way to record and play macros with 3DSlicer. Included in this library is a user-friendly recording interface that shows you what actions you're recording as well as a simple and smart playback interface that will allow you to control actions whenever you want. With no input from the user, QtTesting record all accomplished actions from the point you have started the record until you stop it! "Create a puppet and let it do the rest ... "<br />
<br />
Slicer developers use this library to record tutorials and test the 3D Slicer application. How to create you own [http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/QtTesting QtTesting test]. <br><br />
<br />
<br />
[[Image: QtTestingMenu.png]]<br />
<br />
{{ambox <br />
| text = ''QtTesting is an effort started by the [http://paraview.org/Wiki/Testing_design ParaView team]'' <br />
}}<br />
<br />
==Activate QtTesting==<br />
<br />
{|width="100%"<br />
|valign="top"|<br />
By default, QtTesting is not activated. You must enable it to be able to record or play a saved macro.<br />
* Open the [[Documentation/{{documentation/version}}/SlicerApplication/ApplicationSettings|Application Settings]] dialog.<br />
* On the left side, select the ''QtTesting'' panel<br />
* Enable QtTesting by toggling the checkbox<br />
* Restart Slicer<br />
|align="right"|<br />
[[Image: QtTestingSettigns.png |450px]]<br />
|}<br />
<br />
<br />
==Recorder==<br />
Recording a macro consists in observing all the high level events (or low level in some cases) that the user generate by interacting with the GUI elements. All the events are saved into a file (.xml) that can be used later to [[#Player|replay]] the recorded events in the same or different instance of the Slicer application.<br />
{|width="100%"<br />
|<br />
=== How to record a macro===<br />
* From the [[Documentation/{{documentation/version}}/SlicerApplication/MainApplicationGUI#Application_Menu|menu bar]], open the ''Edit'' menu and select the ''Record Macro'' item to start recording all your following events.<br />
''A record dialog appears at the bottom left of the application''<br />
<br />
=== Record dialog ===<br />
* Shows the last event recorded<br />
* Numbers of events recorded<br />
* ''You can stop the recording anytime by clicking on the Stop button''<br />
<br />
=== Save macro ===<br />
* When the recording is stopped, a dialog shows up to ask where to save the recorded macro file.<br />
<br />
|align="right"|<br />
[[Image: QtTestingRecorderDialog.jpg |300px]]<br />
|}<br />
<br />
<br />
==Player==<br />
Recorded macros (.xml) can be replayed within Slicer sessions. Note that the success of the macro execution can depend on the original state of the application.<br />
<br />
{|width="100%"<br />
|<br />
=== How to play a macro ===<br />
* From the [[Documentation/{{documentation/version}}/SlicerApplication/MainApplicationGUI#Application_Menu|menu bar]], open the ''Edit'' menu and select the ''Play Macro'' item to open the player dialog.<br />
<br />
* Choose the xml macro that you want to play<br />
<br />
* Use the player dialog to start the macro<br />
<br />
Slicer will ask you if you want to restore the previous recorded settings.<br />
<br />
=== Player dialog ===<br />
*'''Controller widget'''<br />
** Play, pause, stop or play-step-by-step your macro.<br />
** ''Logs'' check button shows/hides information about played events and errors if any.<br />
** ''Time step'' controls the playback speed by waiting Xms before playing each event.<br />
<br />
* '''Player tab''' (''default tab'')<br />
** Show the macro file played.<br />
<br />
* '''Info tab''' :<br />
** Show the last event played.<br />
<br />
===Default settings recorded===<br />
To limit playback problems, QtTesting records automatically some of the applications settings.<br />
* General settings :<br />
** The application's geometry<br />
** The application's state<br />
** The application's name<br />
** The application's version<br />
<br />
* 3DSlicer settings :<br />
** The current layout<br />
** The current module<br />
<br />
Before each play back, the application might have different current settings, QtTesting then asks if you want to restore the settings to the record application state. To maximize the chance of a successful playback, settings must be restored to set the application into a state as much as possible similar to when the macro was recorded.<br><br />
{{ambox<br />
| type = speedy<br />
| small = left<br />
| text = It's strongly recommended to accept !<br />
}}<br />
<br />
|align="right"|<br />
[[image: QtTestintPlayererDialog.jpg | 300px]]<br />
[[image: QtTestintRestoreSettingsDialog.png | 300px]]<br />
|}<br />
<br />
<br />
==User limitations==<br />
<br />
''QtTesting in 3DSlicer is still under heavy development, some events might not be recorded properly.''<br />
<br />
===What is subject to not work :===<br />
* Some actions under submenus, mainly actions on widget.<br />
<br />
===Work, but not perfectly:===<br />
* Shifts/offsets might happen when you recording events in the 3D views.</div>BenjaminLonghttps://www.slicer.org/w/index.php?title=Documentation/Nightly/SlicerApplication/QtTesting&diff=26612Documentation/Nightly/SlicerApplication/QtTesting2012-06-05T14:53:33Z<p>BenjaminLong: /* How to record */</p>
<hr />
<div>{|width="100%"<br />
|<br />
__TOC__<br />
|align="right"|<br />
[[Image: 3DSlicerQtTesting.png]]<br />
|}<br />
=Overview=<br />
<br />
Too lazy to do the same actions over and over? QtTesting is the answer! The QtTesting library provides you with an easy way to record and play macros with 3DSlicer. Included in this library is a user-friendly recording interface that shows you what actions you're recording as well as a simple and smart playback interface that will allow you to control actions whenever you want. With no input from the user, QtTesting record all accomplished actions from the point you have started the record until you stop it! "Create a puppet and let it do the rest ... "<br />
<br />
Slicer developers use this library to record tutorials and test the 3D Slicer application. How to create you own [http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/QtTesting QtTesting test]. <br><br />
<br />
<br />
[[Image: QtTestingMenu.png]]<br />
<br />
{{ambox <br />
| text = ''QtTesting is an effort started by the [http://paraview.org/Wiki/Testing_design ParaView team]'' <br />
}}<br />
<br />
==Activate QtTesting==<br />
<br />
{|width="100%"<br />
|valign="top"|<br />
By default, QtTesting is not activated. You must enable it to be able to record or play a saved macro.<br />
* Open the [[Documentation/{{documentation/version}}/SlicerApplication/ApplicationSettings|Application Settings]] dialog.<br />
* On the left side, select the ''QtTesting'' panel<br />
* Enable QtTesting by toggling the checkbox<br />
* Restart Slicer<br />
|align="right"|<br />
[[Image: QtTestingSettigns.png |450px]]<br />
|}<br />
<br />
<br />
==Recorder==<br />
Recording a macro consists in observing all the high level events (or low level in some cases) that the user generate by interacting with the GUI elements. All the events are saved into a file (.xml) that can be used later to [[#Player|replay]] the recorded events in the same or different instance of the Slicer application.<br />
{|width="100%"<br />
|<br />
=== How to record a macro===<br />
* From the [[Documentation/{{documentation/version}}/SlicerApplication/MainApplicationGUI#Application_Menu|menu bar]], open the ''Edit'' menu and select the ''Record Macro'' item to start recording all your following events.<br />
''A record dialog appears at the bottom left of the application''<br />
<br />
=== Record dialog ===<br />
* Shows the last event recorded<br />
* Numbers of events recorded<br />
* ''You can stop the recording anytime by clicking on the Stop button''<br />
<br />
=== Save macro ===<br />
* When the recording is stopped, a dialog shows up to ask where to save the recorded macro file.<br />
<br />
|align="right"|<br />
[[Image: QtTestingRecorderDialog.jpg |300px]]<br />
|}<br />
<br />
<br />
==Player==<br />
Recorded macros (.xml) can be replayed within Slicer sessions. Note that the success of the macro execution can depend on the original state of the application.<br />
<br />
{|width="100%"<br />
|<br />
=== How to play a macro ===<br />
* From the [[Documentation/{{documentation/version}}/SlicerApplication/MainApplicationGUI#Application_Menu|menu bar]], open the ''Edit'' menu and select the ''Play Macro'' item to open the player dialog.<br />
<br />
* Choose the xml macro that you want to play<br />
<br />
* Use the player dialog to start the macro<br />
<br />
=== Player dialog ===<br />
*'''Controller widget'''<br />
** Play, pause, stop or play-step-by-step your macro.<br />
** ''Logs'' check button shows/hides information about played events and errors if any.<br />
** ''Time step'' controls the playback speed by waiting Xms before playing each event.<br />
<br />
* '''Player tab''' (''default tab'')<br />
** Show the macro file played.<br />
<br />
* '''Info tab''' :<br />
** Show the last event played.<br />
<br />
===Default settings recorded===<br />
To limit playback problems, QtTesting records automatically some of the applications settings.<br />
* General settings :<br />
** The application's geometry<br />
** The application's state<br />
** The application's name<br />
** The application's version<br />
<br />
* 3DSlicer settings :<br />
** The current layout<br />
** The current module<br />
<br />
Before each play back, the application might have different current settings, QtTesting then asks if you want to restore the settings to the record application state. To maximize the chance of a successful playback, settings must be restored to set the application into a state as much as possible similar to when the macro was recorded.<br><br />
{{ambox<br />
| type = speedy<br />
| small = left<br />
| text = It's strongly recommended to accept !<br />
}}<br />
<br />
|align="right"|<br />
[[image: QtTestintPlayererDialog.jpg | 300px]]<br />
[[image: QtTestintRestoreSettingsDialog.png | 300px]]<br />
|}<br />
<br />
<br />
==User limitations==<br />
<br />
''QtTesting in 3DSlicer is still under heavy development, some events might not be recorded properly.''<br />
<br />
===What is subject to not work :===<br />
* Some actions under submenus, mainly actions on widget.<br />
<br />
===Work, but not perfectly:===<br />
* Shifts/offsets might happen when you recording events in the 3D views.</div>BenjaminLonghttps://www.slicer.org/w/index.php?title=Documentation/Nightly/SlicerApplication/QtTesting&diff=26611Documentation/Nightly/SlicerApplication/QtTesting2012-06-05T14:53:24Z<p>BenjaminLong: /* How to Start */</p>
<hr />
<div>{|width="100%"<br />
|<br />
__TOC__<br />
|align="right"|<br />
[[Image: 3DSlicerQtTesting.png]]<br />
|}<br />
=Overview=<br />
<br />
Too lazy to do the same actions over and over? QtTesting is the answer! The QtTesting library provides you with an easy way to record and play macros with 3DSlicer. Included in this library is a user-friendly recording interface that shows you what actions you're recording as well as a simple and smart playback interface that will allow you to control actions whenever you want. With no input from the user, QtTesting record all accomplished actions from the point you have started the record until you stop it! "Create a puppet and let it do the rest ... "<br />
<br />
Slicer developers use this library to record tutorials and test the 3D Slicer application. How to create you own [http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/QtTesting QtTesting test]. <br><br />
<br />
<br />
[[Image: QtTestingMenu.png]]<br />
<br />
{{ambox <br />
| text = ''QtTesting is an effort started by the [http://paraview.org/Wiki/Testing_design ParaView team]'' <br />
}}<br />
<br />
==Activate QtTesting==<br />
<br />
{|width="100%"<br />
|valign="top"|<br />
By default, QtTesting is not activated. You must enable it to be able to record or play a saved macro.<br />
* Open the [[Documentation/{{documentation/version}}/SlicerApplication/ApplicationSettings|Application Settings]] dialog.<br />
* On the left side, select the ''QtTesting'' panel<br />
* Enable QtTesting by toggling the checkbox<br />
* Restart Slicer<br />
|align="right"|<br />
[[Image: QtTestingSettigns.png |450px]]<br />
|}<br />
<br />
<br />
==Recorder==<br />
Recording a macro consists in observing all the high level events (or low level in some cases) that the user generate by interacting with the GUI elements. All the events are saved into a file (.xml) that can be used later to [[#Player|replay]] the recorded events in the same or different instance of the Slicer application.<br />
{|width="100%"<br />
|<br />
=== How to record ===<br />
* From the [[Documentation/{{documentation/version}}/SlicerApplication/MainApplicationGUI#Application_Menu|menu bar]], open the ''Edit'' menu and select the ''Record Macro'' item to start recording all your following events.<br />
''A record dialog appears at the bottom left of the application''<br />
<br />
=== Record dialog ===<br />
* Shows the last event recorded<br />
* Numbers of events recorded<br />
* ''You can stop the recording anytime by clicking on the Stop button''<br />
<br />
=== Save macro ===<br />
* When the recording is stopped, a dialog shows up to ask where to save the recorded macro file.<br />
<br />
|align="right"|<br />
[[Image: QtTestingRecorderDialog.jpg |300px]]<br />
|}<br />
<br />
<br />
==Player==<br />
Recorded macros (.xml) can be replayed within Slicer sessions. Note that the success of the macro execution can depend on the original state of the application.<br />
<br />
{|width="100%"<br />
|<br />
=== How to play a macro ===<br />
* From the [[Documentation/{{documentation/version}}/SlicerApplication/MainApplicationGUI#Application_Menu|menu bar]], open the ''Edit'' menu and select the ''Play Macro'' item to open the player dialog.<br />
<br />
* Choose the xml macro that you want to play<br />
<br />
* Use the player dialog to start the macro<br />
<br />
=== Player dialog ===<br />
*'''Controller widget'''<br />
** Play, pause, stop or play-step-by-step your macro.<br />
** ''Logs'' check button shows/hides information about played events and errors if any.<br />
** ''Time step'' controls the playback speed by waiting Xms before playing each event.<br />
<br />
* '''Player tab''' (''default tab'')<br />
** Show the macro file played.<br />
<br />
* '''Info tab''' :<br />
** Show the last event played.<br />
<br />
===Default settings recorded===<br />
To limit playback problems, QtTesting records automatically some of the applications settings.<br />
* General settings :<br />
** The application's geometry<br />
** The application's state<br />
** The application's name<br />
** The application's version<br />
<br />
* 3DSlicer settings :<br />
** The current layout<br />
** The current module<br />
<br />
Before each play back, the application might have different current settings, QtTesting then asks if you want to restore the settings to the record application state. To maximize the chance of a successful playback, settings must be restored to set the application into a state as much as possible similar to when the macro was recorded.<br><br />
{{ambox<br />
| type = speedy<br />
| small = left<br />
| text = It's strongly recommended to accept !<br />
}}<br />
<br />
|align="right"|<br />
[[image: QtTestintPlayererDialog.jpg | 300px]]<br />
[[image: QtTestintRestoreSettingsDialog.png | 300px]]<br />
|}<br />
<br />
<br />
==User limitations==<br />
<br />
''QtTesting in 3DSlicer is still under heavy development, some events might not be recorded properly.''<br />
<br />
===What is subject to not work :===<br />
* Some actions under submenus, mainly actions on widget.<br />
<br />
===Work, but not perfectly:===<br />
* Shifts/offsets might happen when you recording events in the 3D views.</div>BenjaminLonghttps://www.slicer.org/w/index.php?title=Documentation/Nightly/SlicerApplication/QtTesting&diff=26610Documentation/Nightly/SlicerApplication/QtTesting2012-06-05T14:52:25Z<p>BenjaminLong: /* Start recording */</p>
<hr />
<div>{|width="100%"<br />
|<br />
__TOC__<br />
|align="right"|<br />
[[Image: 3DSlicerQtTesting.png]]<br />
|}<br />
=Overview=<br />
<br />
Too lazy to do the same actions over and over? QtTesting is the answer! The QtTesting library provides you with an easy way to record and play macros with 3DSlicer. Included in this library is a user-friendly recording interface that shows you what actions you're recording as well as a simple and smart playback interface that will allow you to control actions whenever you want. With no input from the user, QtTesting record all accomplished actions from the point you have started the record until you stop it! "Create a puppet and let it do the rest ... "<br />
<br />
Slicer developers use this library to record tutorials and test the 3D Slicer application. How to create you own [http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/QtTesting QtTesting test]. <br><br />
<br />
<br />
[[Image: QtTestingMenu.png]]<br />
<br />
{{ambox <br />
| text = ''QtTesting is an effort started by the [http://paraview.org/Wiki/Testing_design ParaView team]'' <br />
}}<br />
<br />
==Activate QtTesting==<br />
<br />
{|width="100%"<br />
|valign="top"|<br />
By default, QtTesting is not activated. You must enable it to be able to record or play a saved macro.<br />
* Open the [[Documentation/{{documentation/version}}/SlicerApplication/ApplicationSettings|Application Settings]] dialog.<br />
* On the left side, select the ''QtTesting'' panel<br />
* Enable QtTesting by toggling the checkbox<br />
* Restart Slicer<br />
|align="right"|<br />
[[Image: QtTestingSettigns.png |450px]]<br />
|}<br />
<br />
<br />
==Recorder==<br />
Recording a macro consists in observing all the high level events (or low level in some cases) that the user generate by interacting with the GUI elements. All the events are saved into a file (.xml) that can be used later to [[#Player|replay]] the recorded events in the same or different instance of the Slicer application.<br />
{|width="100%"<br />
|<br />
=== How to record ===<br />
* From the [[Documentation/{{documentation/version}}/SlicerApplication/MainApplicationGUI#Application_Menu|menu bar]], open the ''Edit'' menu and select the ''Record Macro'' item to start recording all your following events.<br />
''A record dialog appears at the bottom left of the application''<br />
<br />
=== Record dialog ===<br />
* Shows the last event recorded<br />
* Numbers of events recorded<br />
* ''You can stop the recording anytime by clicking on the Stop button''<br />
<br />
=== Save macro ===<br />
* When the recording is stopped, a dialog shows up to ask where to save the recorded macro file.<br />
<br />
|align="right"|<br />
[[Image: QtTestingRecorderDialog.jpg |300px]]<br />
|}<br />
<br />
<br />
==Player==<br />
Recorded macros (.xml) can be replayed within Slicer sessions. Note that the success of the macro execution can depend on the original state of the application.<br />
<br />
{|width="100%"<br />
|<br />
=== How to Start ===<br />
* From the [[Documentation/{{documentation/version}}/SlicerApplication/MainApplicationGUI#Application_Menu|menu bar]], open the ''Edit'' menu and select the ''Play Macro'' item to open the player dialog.<br />
<br />
* Choose the xml macro that you want to play<br />
<br />
* Use the player dialog to start the macro<br />
<br />
=== Player dialog ===<br />
*'''Controller widget'''<br />
** Play, pause, stop or play-step-by-step your macro.<br />
** ''Logs'' check button shows/hides information about played events and errors if any.<br />
** ''Time step'' controls the playback speed by waiting Xms before playing each event.<br />
<br />
* '''Player tab''' (''default tab'')<br />
** Show the macro file played.<br />
<br />
* '''Info tab''' :<br />
** Show the last event played.<br />
<br />
===Default settings recorded===<br />
To limit playback problems, QtTesting records automatically some of the applications settings.<br />
* General settings :<br />
** The application's geometry<br />
** The application's state<br />
** The application's name<br />
** The application's version<br />
<br />
* 3DSlicer settings :<br />
** The current layout<br />
** The current module<br />
<br />
Before each play back, the application might have different current settings, QtTesting then asks if you want to restore the settings to the record application state. To maximize the chance of a successful playback, settings must be restored to set the application into a state as much as possible similar to when the macro was recorded.<br><br />
{{ambox<br />
| type = speedy<br />
| small = left<br />
| text = It's strongly recommended to accept !<br />
}}<br />
<br />
|align="right"|<br />
[[image: QtTestintPlayererDialog.jpg | 300px]]<br />
[[image: QtTestintRestoreSettingsDialog.png | 300px]]<br />
|}<br />
<br />
<br />
==User limitations==<br />
<br />
''QtTesting in 3DSlicer is still under heavy development, some events might not be recorded properly.''<br />
<br />
===What is subject to not work :===<br />
* Some actions under submenus, mainly actions on widget.<br />
<br />
===Work, but not perfectly:===<br />
* Shifts/offsets might happen when you recording events in the 3D views.</div>BenjaminLonghttps://www.slicer.org/w/index.php?title=Documentation/Nightly/SlicerApplication/QtTesting&diff=26609Documentation/Nightly/SlicerApplication/QtTesting2012-06-05T14:49:13Z<p>BenjaminLong: /* How to Start */</p>
<hr />
<div>{|width="100%"<br />
|<br />
__TOC__<br />
|align="right"|<br />
[[Image: 3DSlicerQtTesting.png]]<br />
|}<br />
=Overview=<br />
<br />
Too lazy to do the same actions over and over? QtTesting is the answer! The QtTesting library provides you with an easy way to record and play macros with 3DSlicer. Included in this library is a user-friendly recording interface that shows you what actions you're recording as well as a simple and smart playback interface that will allow you to control actions whenever you want. With no input from the user, QtTesting record all accomplished actions from the point you have started the record until you stop it! "Create a puppet and let it do the rest ... "<br />
<br />
Slicer developers use this library to record tutorials and test the 3D Slicer application. How to create you own [http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/QtTesting QtTesting test]. <br><br />
<br />
<br />
[[Image: QtTestingMenu.png]]<br />
<br />
{{ambox <br />
| text = ''QtTesting is an effort started by the [http://paraview.org/Wiki/Testing_design ParaView team]'' <br />
}}<br />
<br />
==Activate QtTesting==<br />
<br />
{|width="100%"<br />
|valign="top"|<br />
By default, QtTesting is not activated. You must enable it to be able to record or play a saved macro.<br />
* Open the [[Documentation/{{documentation/version}}/SlicerApplication/ApplicationSettings|Application Settings]] dialog.<br />
* On the left side, select the ''QtTesting'' panel<br />
* Enable QtTesting by toggling the checkbox<br />
* Restart Slicer<br />
|align="right"|<br />
[[Image: QtTestingSettigns.png |450px]]<br />
|}<br />
<br />
<br />
==Recorder==<br />
Recording a macro consists in observing all the high level events (or low level in some cases) that the user generate by interacting with the GUI elements. All the events are saved into a file (.xml) that can be used later to [[#Player|replay]] the recorded events in the same or different instance of the Slicer application.<br />
{|width="100%"<br />
|<br />
=== Start recording ===<br />
* From the [[Documentation/{{documentation/version}}/SlicerApplication/MainApplicationGUI#Application_Menu|menu bar]], open the ''Edit'' menu and select the ''Record Macro'' item to start recording all your following events.<br />
''A record dialog appears at the bottom left of the application''<br />
<br />
=== Record dialog ===<br />
* Shows the last event recorded<br />
* Numbers of events recorded<br />
* ''You can stop the recording anytime by clicking on the Stop button''<br />
<br />
=== Save macro ===<br />
* When the recording is stopped, a dialog shows up to ask where to save the recorded macro file.<br />
<br />
|align="right"|<br />
[[Image: QtTestingRecorderDialog.jpg |300px]]<br />
|}<br />
<br />
<br />
==Player==<br />
Recorded macros (.xml) can be replayed within Slicer sessions. Note that the success of the macro execution can depend on the original state of the application.<br />
<br />
{|width="100%"<br />
|<br />
=== How to Start ===<br />
* From the [[Documentation/{{documentation/version}}/SlicerApplication/MainApplicationGUI#Application_Menu|menu bar]], open the ''Edit'' menu and select the ''Play Macro'' item to open the player dialog.<br />
<br />
* Choose the xml macro that you want to play<br />
<br />
* Use the player dialog to start the macro<br />
<br />
=== Player dialog ===<br />
*'''Controller widget'''<br />
** Play, pause, stop or play-step-by-step your macro.<br />
** ''Logs'' check button shows/hides information about played events and errors if any.<br />
** ''Time step'' controls the playback speed by waiting Xms before playing each event.<br />
<br />
* '''Player tab''' (''default tab'')<br />
** Show the macro file played.<br />
<br />
* '''Info tab''' :<br />
** Show the last event played.<br />
<br />
===Default settings recorded===<br />
To limit playback problems, QtTesting records automatically some of the applications settings.<br />
* General settings :<br />
** The application's geometry<br />
** The application's state<br />
** The application's name<br />
** The application's version<br />
<br />
* 3DSlicer settings :<br />
** The current layout<br />
** The current module<br />
<br />
Before each play back, the application might have different current settings, QtTesting then asks if you want to restore the settings to the record application state. To maximize the chance of a successful playback, settings must be restored to set the application into a state as much as possible similar to when the macro was recorded.<br><br />
{{ambox<br />
| type = speedy<br />
| small = left<br />
| text = It's strongly recommended to accept !<br />
}}<br />
<br />
|align="right"|<br />
[[image: QtTestintPlayererDialog.jpg | 300px]]<br />
[[image: QtTestintRestoreSettingsDialog.png | 300px]]<br />
|}<br />
<br />
<br />
==User limitations==<br />
<br />
''QtTesting in 3DSlicer is still under heavy development, some events might not be recorded properly.''<br />
<br />
===What is subject to not work :===<br />
* Some actions under submenus, mainly actions on widget.<br />
<br />
===Work, but not perfectly:===<br />
* Shifts/offsets might happen when you recording events in the 3D views.</div>BenjaminLonghttps://www.slicer.org/w/index.php?title=Documentation/Nightly/Developers/QtTesting&diff=26608Documentation/Nightly/Developers/QtTesting2012-06-05T14:11:40Z<p>BenjaminLong: /* Rules for Developers */</p>
<hr />
<div>{|width="100%"<br />
|<br />
__TOC__<br />
|align="right"|<br />
[[Image: 3DSlicerQtTesting.png]]<br />
|}<br />
=Overview=<br />
<br />
QtTesting provides us a testing framework to test our application. It complements unit tests, by testing the application in its globality.<br />
<br />
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.<br><br />
<br />
=Rules for Developers=<br />
<br />
QtTesting records high level events, and try to not record mouse events as mouse press, release or move.<br><br />
Furthermore, QtTesting is still under heavy development and some low level events won't be properly recorded.<br><br />
<br />
'''Please be aware of those following warning :''' <br />
<br />
* Use '''''"activated"''''' signal instead of '''''"clicked"''''', when connection Qt views<br />
<br />
=Write a 3DSlicer test using QtTesting=<br />
<br />
QtTesting framework can also be use to create module test.<br> Use the description below, but instead of <code>Slicer4/Applications/SlicerApp/Testing</code> all the path start by <code>Slicer4/Path/To/The/Modules/Testing</code><br />
<br />
Following is the different step to create a test using QtTesting framework. <br />
<br />
== Create your XML script ==<br />
See [http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/SlicerApplication/QtTesting QtTesting user Wiki] to know how to create this xml script.<br><br />
'''Save the xml script to''' <code>Slicer4/Applications/SlicerApp/Data/Input/MYTUTORIALNAME.xml''</code><br><br />
{{ambox <br />
| type = content<br />
|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]<br><br />
[[Documentation/{{documentation/version}}/Modules/SampleData Sample Data]] module according to the current Slicer version<br />
}}<br />
<br />
== Create a Python script ==<br />
''This Python test will start 3DSlicer and run the previously recorded xml script''<br />
<br />
'''''Create a python file with the following lines'''''<br />
<br />
import os<br />
import slicer<br />
import ApplicationsSlicerAppData as data<br />
filepath = data.input + '/MYTUTORIALNAME.xml') ex : NeurosurgicalPlanningTutorial.xml<br />
testUtility = slicer.app.testingUtility()<br />
success = testUtility.playTests(filepath)<br />
if not success :<br />
raise Exception('Failed to finished properly the play back !')<br />
<br />
'''''Save to the directory ''''' <code>Slicer4/Applications/SlicerApp/Testing/Python/MYTUTORIALNAME.py </code><br />
<br />
== Add the test in CMake ==<br />
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.<br />
<br />
Edit the file <code>Slicer4/Applications/SlicerApp/Testing/Python/CMakeLists.txt</code><br><br />
Add your test at the end of the Slicer_USE_QTTESTING condition and add the name in the <code>set_tests_properties</code> function :<br />
<br />
if(Slicer_USE_QTTESTING)<br />
{ <br />
...<br />
slicer_add_python_test(<br />
SCRIPT MYTUTORIALNAME.py<br />
SLICER_ARGS --launcher-no-splash --qt-testing)<br />
set_tests_properties(<br />
py_NeurosurgicalPlanningTutorial<br />
py_DiffusionTensorImagingTutorial<br />
....<br />
py_MYTUTORIALNAME<br />
...<br />
PROPERTIES RUN_SERIAL ON<br />
)<br />
}<br />
<br />
<br />
You just wrote a Slicer Unit Test using QtTesting framework !<br />
<br />
== Run your test==<br />
<br />
You can either use directly CTest or the pyhton script created.<br />
<br />
===Using CTest===<br />
{|width = "100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer4-Superbuild/Slicer-build<br />
$ ctest -R MYTUTORIALNAME -VV<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer4-Superbuild\Slicer-build<br />
$ path\to\cmake\ctest.exe -R MYTUTORIALNAME -VV<br />
|}<br />
<br />
===Using the python script===<br />
{|width="100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer4/Application/SlicerApp/Testing/Python<br />
$ python MYTUTORIALNAME.py<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer4\Applicaiton\SlicerApp\Testing\Python<br />
$ path\to\Slicer4-Superbuild\python-build\PCBuild\python.exe MYTUTORIALNAME.py<br />
|}<br />
<br />
=Create custom translator/player=<br />
<br />
After created a custom widget, it might be possible that all its actions are not properly recorded, or played.<br><br />
QtTesting provides us basic translator and player template, to create our custom translator and player according to the widget. <br><br />
<br />
You can use the following command to create those basic files.<br />
<br />
{|width="100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer4-Superbuild/CTK-build/QtTesting/Utilities/Scripts<br />
$ python TranslatorPlayerWizard.py MY_WIDGET_NAME<br />
$ cd ../MY_WIDGET_NAME<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer4-Superbuild<br />
$ python-build\PCBuild\python.exe CTK-build\QtTesting\Utilities\Scripts\TranslatorPlayerWizard.py MY_WIDGET_NAME<br />
$ cd ../MY_WIDGET_NAME<br />
|}<br />
<br />
{{ambox<br />
| type = <br />
| text = 4 files should have been created ! <br> <br />
<code>MY_WIDGET_NAMETranslator.cpp <br> <br />
MY_WIDGET_NAMETranslator.h <br> <br />
MY_WIDGET_NAMEPlayer.cpp <br> <br />
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.<br />
}}<br />
<br />
Finally move the 4 files to the same directory as your widget<br />
<br />
$ cd path/to/Slicer4-Superbuild/CTK-build/QtTesting/Utilities/MY_WIDGET_NAME<br />
$ mv MY_WIDGET_NAMETranslator.cpp MY_WIDGET_NAMETranslator.h MY_WIDGET_NAMEPlayer.cpp MY_WIDGET_NAMEPlayer.h Path/To/My/Widget/Directory<br />
<br />
or just a simple copy to the same directory as your widget<br />
<br />
$ cp MY_WIDGET_NAMETranslator.cpp MY_WIDGET_NAMETranslator.h MY_WIDGET_NAMEPlayer.cpp MY_WIDGET_NAMEPlayer.h Path/To/My/Widget/Directory<br />
<br />
=Open bugs=<br />
Work in progress, following the two bug trackers :<br />
<br />
[http://na-mic.org/Mantis/search.php?project_id=3&category=QtTesting&sticky_issues=off&sortby=last_updated&dir=DESC&hide_status_id=-2 Slicer issues]<br />
<br />
[https://github.com/commontk/CTK/issues?labels=Testing&milestone=&page=1&state=open QtTesting issues]</div>BenjaminLonghttps://www.slicer.org/w/index.php?title=Documentation/Nightly/Developers/QtTesting&diff=26607Documentation/Nightly/Developers/QtTesting2012-06-05T14:11:00Z<p>BenjaminLong: /* Rules for Developers */</p>
<hr />
<div>{|width="100%"<br />
|<br />
__TOC__<br />
|align="right"|<br />
[[Image: 3DSlicerQtTesting.png]]<br />
|}<br />
=Overview=<br />
<br />
QtTesting provides us a testing framework to test our application. It complements unit tests, by testing the application in its globality.<br />
<br />
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.<br><br />
<br />
=Rules for Developers=<br />
<br />
QtTesting records high level events, and try to not record mouse events as mouse press, release or move.<br><br />
Furthermore, QtTesting is still under heavy development and some low level events won't be properly recorded.<br><br />
<br />
'''''Please be aware of those following warning :''''' <br />
<br />
* Use "activated" signal instead of "clicked", when connection Qt views<br />
<br />
=Write a 3DSlicer test using QtTesting=<br />
<br />
QtTesting framework can also be use to create module test.<br> Use the description below, but instead of <code>Slicer4/Applications/SlicerApp/Testing</code> all the path start by <code>Slicer4/Path/To/The/Modules/Testing</code><br />
<br />
Following is the different step to create a test using QtTesting framework. <br />
<br />
== Create your XML script ==<br />
See [http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/SlicerApplication/QtTesting QtTesting user Wiki] to know how to create this xml script.<br><br />
'''Save the xml script to''' <code>Slicer4/Applications/SlicerApp/Data/Input/MYTUTORIALNAME.xml''</code><br><br />
{{ambox <br />
| type = content<br />
|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]<br><br />
[[Documentation/{{documentation/version}}/Modules/SampleData Sample Data]] module according to the current Slicer version<br />
}}<br />
<br />
== Create a Python script ==<br />
''This Python test will start 3DSlicer and run the previously recorded xml script''<br />
<br />
'''''Create a python file with the following lines'''''<br />
<br />
import os<br />
import slicer<br />
import ApplicationsSlicerAppData as data<br />
filepath = data.input + '/MYTUTORIALNAME.xml') ex : NeurosurgicalPlanningTutorial.xml<br />
testUtility = slicer.app.testingUtility()<br />
success = testUtility.playTests(filepath)<br />
if not success :<br />
raise Exception('Failed to finished properly the play back !')<br />
<br />
'''''Save to the directory ''''' <code>Slicer4/Applications/SlicerApp/Testing/Python/MYTUTORIALNAME.py </code><br />
<br />
== Add the test in CMake ==<br />
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.<br />
<br />
Edit the file <code>Slicer4/Applications/SlicerApp/Testing/Python/CMakeLists.txt</code><br><br />
Add your test at the end of the Slicer_USE_QTTESTING condition and add the name in the <code>set_tests_properties</code> function :<br />
<br />
if(Slicer_USE_QTTESTING)<br />
{ <br />
...<br />
slicer_add_python_test(<br />
SCRIPT MYTUTORIALNAME.py<br />
SLICER_ARGS --launcher-no-splash --qt-testing)<br />
set_tests_properties(<br />
py_NeurosurgicalPlanningTutorial<br />
py_DiffusionTensorImagingTutorial<br />
....<br />
py_MYTUTORIALNAME<br />
...<br />
PROPERTIES RUN_SERIAL ON<br />
)<br />
}<br />
<br />
<br />
You just wrote a Slicer Unit Test using QtTesting framework !<br />
<br />
== Run your test==<br />
<br />
You can either use directly CTest or the pyhton script created.<br />
<br />
===Using CTest===<br />
{|width = "100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer4-Superbuild/Slicer-build<br />
$ ctest -R MYTUTORIALNAME -VV<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer4-Superbuild\Slicer-build<br />
$ path\to\cmake\ctest.exe -R MYTUTORIALNAME -VV<br />
|}<br />
<br />
===Using the python script===<br />
{|width="100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer4/Application/SlicerApp/Testing/Python<br />
$ python MYTUTORIALNAME.py<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer4\Applicaiton\SlicerApp\Testing\Python<br />
$ path\to\Slicer4-Superbuild\python-build\PCBuild\python.exe MYTUTORIALNAME.py<br />
|}<br />
<br />
=Create custom translator/player=<br />
<br />
After created a custom widget, it might be possible that all its actions are not properly recorded, or played.<br><br />
QtTesting provides us basic translator and player template, to create our custom translator and player according to the widget. <br><br />
<br />
You can use the following command to create those basic files.<br />
<br />
{|width="100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer4-Superbuild/CTK-build/QtTesting/Utilities/Scripts<br />
$ python TranslatorPlayerWizard.py MY_WIDGET_NAME<br />
$ cd ../MY_WIDGET_NAME<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer4-Superbuild<br />
$ python-build\PCBuild\python.exe CTK-build\QtTesting\Utilities\Scripts\TranslatorPlayerWizard.py MY_WIDGET_NAME<br />
$ cd ../MY_WIDGET_NAME<br />
|}<br />
<br />
{{ambox<br />
| type = <br />
| text = 4 files should have been created ! <br> <br />
<code>MY_WIDGET_NAMETranslator.cpp <br> <br />
MY_WIDGET_NAMETranslator.h <br> <br />
MY_WIDGET_NAMEPlayer.cpp <br> <br />
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.<br />
}}<br />
<br />
Finally move the 4 files to the same directory as your widget<br />
<br />
$ cd path/to/Slicer4-Superbuild/CTK-build/QtTesting/Utilities/MY_WIDGET_NAME<br />
$ mv MY_WIDGET_NAMETranslator.cpp MY_WIDGET_NAMETranslator.h MY_WIDGET_NAMEPlayer.cpp MY_WIDGET_NAMEPlayer.h Path/To/My/Widget/Directory<br />
<br />
or just a simple copy to the same directory as your widget<br />
<br />
$ cp MY_WIDGET_NAMETranslator.cpp MY_WIDGET_NAMETranslator.h MY_WIDGET_NAMEPlayer.cpp MY_WIDGET_NAMEPlayer.h Path/To/My/Widget/Directory<br />
<br />
=Open bugs=<br />
Work in progress, following the two bug trackers :<br />
<br />
[http://na-mic.org/Mantis/search.php?project_id=3&category=QtTesting&sticky_issues=off&sortby=last_updated&dir=DESC&hide_status_id=-2 Slicer issues]<br />
<br />
[https://github.com/commontk/CTK/issues?labels=Testing&milestone=&page=1&state=open QtTesting issues]</div>BenjaminLonghttps://www.slicer.org/w/index.php?title=Documentation/Nightly/Developers/QtTesting&diff=26606Documentation/Nightly/Developers/QtTesting2012-06-05T14:08:35Z<p>BenjaminLong: /* Rules for Developers */</p>
<hr />
<div>{|width="100%"<br />
|<br />
__TOC__<br />
|align="right"|<br />
[[Image: 3DSlicerQtTesting.png]]<br />
|}<br />
=Overview=<br />
<br />
QtTesting provides us a testing framework to test our application. It complements unit tests, by testing the application in its globality.<br />
<br />
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.<br><br />
<br />
=Rules for Developers=<br />
<br />
QtTesting records high level events, and try to not record mouse events as mouse press, release or move.<br><br />
Furthermore, QtTesting is still under heavy development and some low level events won't be properly recorded.<br><br />
<br />
Please be aware of those following warning : <br />
<br />
* use "activated" signal instead of "clicked"<br />
<br />
=Write a 3DSlicer test using QtTesting=<br />
<br />
QtTesting framework can also be use to create module test.<br> Use the description below, but instead of <code>Slicer4/Applications/SlicerApp/Testing</code> all the path start by <code>Slicer4/Path/To/The/Modules/Testing</code><br />
<br />
Following is the different step to create a test using QtTesting framework. <br />
<br />
== Create your XML script ==<br />
See [http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/SlicerApplication/QtTesting QtTesting user Wiki] to know how to create this xml script.<br><br />
'''Save the xml script to''' <code>Slicer4/Applications/SlicerApp/Data/Input/MYTUTORIALNAME.xml''</code><br><br />
{{ambox <br />
| type = content<br />
|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]<br><br />
[[Documentation/{{documentation/version}}/Modules/SampleData Sample Data]] module according to the current Slicer version<br />
}}<br />
<br />
== Create a Python script ==<br />
''This Python test will start 3DSlicer and run the previously recorded xml script''<br />
<br />
'''''Create a python file with the following lines'''''<br />
<br />
import os<br />
import slicer<br />
import ApplicationsSlicerAppData as data<br />
filepath = data.input + '/MYTUTORIALNAME.xml') ex : NeurosurgicalPlanningTutorial.xml<br />
testUtility = slicer.app.testingUtility()<br />
success = testUtility.playTests(filepath)<br />
if not success :<br />
raise Exception('Failed to finished properly the play back !')<br />
<br />
'''''Save to the directory ''''' <code>Slicer4/Applications/SlicerApp/Testing/Python/MYTUTORIALNAME.py </code><br />
<br />
== Add the test in CMake ==<br />
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.<br />
<br />
Edit the file <code>Slicer4/Applications/SlicerApp/Testing/Python/CMakeLists.txt</code><br><br />
Add your test at the end of the Slicer_USE_QTTESTING condition and add the name in the <code>set_tests_properties</code> function :<br />
<br />
if(Slicer_USE_QTTESTING)<br />
{ <br />
...<br />
slicer_add_python_test(<br />
SCRIPT MYTUTORIALNAME.py<br />
SLICER_ARGS --launcher-no-splash --qt-testing)<br />
set_tests_properties(<br />
py_NeurosurgicalPlanningTutorial<br />
py_DiffusionTensorImagingTutorial<br />
....<br />
py_MYTUTORIALNAME<br />
...<br />
PROPERTIES RUN_SERIAL ON<br />
)<br />
}<br />
<br />
<br />
You just wrote a Slicer Unit Test using QtTesting framework !<br />
<br />
== Run your test==<br />
<br />
You can either use directly CTest or the pyhton script created.<br />
<br />
===Using CTest===<br />
{|width = "100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer4-Superbuild/Slicer-build<br />
$ ctest -R MYTUTORIALNAME -VV<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer4-Superbuild\Slicer-build<br />
$ path\to\cmake\ctest.exe -R MYTUTORIALNAME -VV<br />
|}<br />
<br />
===Using the python script===<br />
{|width="100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer4/Application/SlicerApp/Testing/Python<br />
$ python MYTUTORIALNAME.py<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer4\Applicaiton\SlicerApp\Testing\Python<br />
$ path\to\Slicer4-Superbuild\python-build\PCBuild\python.exe MYTUTORIALNAME.py<br />
|}<br />
<br />
=Create custom translator/player=<br />
<br />
After created a custom widget, it might be possible that all its actions are not properly recorded, or played.<br><br />
QtTesting provides us basic translator and player template, to create our custom translator and player according to the widget. <br><br />
<br />
You can use the following command to create those basic files.<br />
<br />
{|width="100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer4-Superbuild/CTK-build/QtTesting/Utilities/Scripts<br />
$ python TranslatorPlayerWizard.py MY_WIDGET_NAME<br />
$ cd ../MY_WIDGET_NAME<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer4-Superbuild<br />
$ python-build\PCBuild\python.exe CTK-build\QtTesting\Utilities\Scripts\TranslatorPlayerWizard.py MY_WIDGET_NAME<br />
$ cd ../MY_WIDGET_NAME<br />
|}<br />
<br />
{{ambox<br />
| type = <br />
| text = 4 files should have been created ! <br> <br />
<code>MY_WIDGET_NAMETranslator.cpp <br> <br />
MY_WIDGET_NAMETranslator.h <br> <br />
MY_WIDGET_NAMEPlayer.cpp <br> <br />
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.<br />
}}<br />
<br />
Finally move the 4 files to the same directory as your widget<br />
<br />
$ cd path/to/Slicer4-Superbuild/CTK-build/QtTesting/Utilities/MY_WIDGET_NAME<br />
$ mv MY_WIDGET_NAMETranslator.cpp MY_WIDGET_NAMETranslator.h MY_WIDGET_NAMEPlayer.cpp MY_WIDGET_NAMEPlayer.h Path/To/My/Widget/Directory<br />
<br />
or just a simple copy to the same directory as your widget<br />
<br />
$ cp MY_WIDGET_NAMETranslator.cpp MY_WIDGET_NAMETranslator.h MY_WIDGET_NAMEPlayer.cpp MY_WIDGET_NAMEPlayer.h Path/To/My/Widget/Directory<br />
<br />
=Open bugs=<br />
Work in progress, following the two bug trackers :<br />
<br />
[http://na-mic.org/Mantis/search.php?project_id=3&category=QtTesting&sticky_issues=off&sortby=last_updated&dir=DESC&hide_status_id=-2 Slicer issues]<br />
<br />
[https://github.com/commontk/CTK/issues?labels=Testing&milestone=&page=1&state=open QtTesting issues]</div>BenjaminLonghttps://www.slicer.org/w/index.php?title=Documentation/Nightly/Developers/QtTesting&diff=26605Documentation/Nightly/Developers/QtTesting2012-06-05T14:07:30Z<p>BenjaminLong: /* Rule for Developers */</p>
<hr />
<div>{|width="100%"<br />
|<br />
__TOC__<br />
|align="right"|<br />
[[Image: 3DSlicerQtTesting.png]]<br />
|}<br />
=Overview=<br />
<br />
QtTesting provides us a testing framework to test our application. It complements unit tests, by testing the application in its globality.<br />
<br />
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.<br><br />
<br />
=Rules for Developers=<br />
<br />
QtTesting records high level events, and try to not record mouse events as mouse press, release or move.<br><br />
Furthermore, QtTesting is still under heavy development and and some low level event won't be properly recorded.<br />
<br />
# use "activated" signal instead of "clicked"<br />
<br />
=Write a 3DSlicer test using QtTesting=<br />
<br />
QtTesting framework can also be use to create module test.<br> Use the description below, but instead of <code>Slicer4/Applications/SlicerApp/Testing</code> all the path start by <code>Slicer4/Path/To/The/Modules/Testing</code><br />
<br />
Following is the different step to create a test using QtTesting framework. <br />
<br />
== Create your XML script ==<br />
See [http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/SlicerApplication/QtTesting QtTesting user Wiki] to know how to create this xml script.<br><br />
'''Save the xml script to''' <code>Slicer4/Applications/SlicerApp/Data/Input/MYTUTORIALNAME.xml''</code><br><br />
{{ambox <br />
| type = content<br />
|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]<br><br />
[[Documentation/{{documentation/version}}/Modules/SampleData Sample Data]] module according to the current Slicer version<br />
}}<br />
<br />
== Create a Python script ==<br />
''This Python test will start 3DSlicer and run the previously recorded xml script''<br />
<br />
'''''Create a python file with the following lines'''''<br />
<br />
import os<br />
import slicer<br />
import ApplicationsSlicerAppData as data<br />
filepath = data.input + '/MYTUTORIALNAME.xml') ex : NeurosurgicalPlanningTutorial.xml<br />
testUtility = slicer.app.testingUtility()<br />
success = testUtility.playTests(filepath)<br />
if not success :<br />
raise Exception('Failed to finished properly the play back !')<br />
<br />
'''''Save to the directory ''''' <code>Slicer4/Applications/SlicerApp/Testing/Python/MYTUTORIALNAME.py </code><br />
<br />
== Add the test in CMake ==<br />
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.<br />
<br />
Edit the file <code>Slicer4/Applications/SlicerApp/Testing/Python/CMakeLists.txt</code><br><br />
Add your test at the end of the Slicer_USE_QTTESTING condition and add the name in the <code>set_tests_properties</code> function :<br />
<br />
if(Slicer_USE_QTTESTING)<br />
{ <br />
...<br />
slicer_add_python_test(<br />
SCRIPT MYTUTORIALNAME.py<br />
SLICER_ARGS --launcher-no-splash --qt-testing)<br />
set_tests_properties(<br />
py_NeurosurgicalPlanningTutorial<br />
py_DiffusionTensorImagingTutorial<br />
....<br />
py_MYTUTORIALNAME<br />
...<br />
PROPERTIES RUN_SERIAL ON<br />
)<br />
}<br />
<br />
<br />
You just wrote a Slicer Unit Test using QtTesting framework !<br />
<br />
== Run your test==<br />
<br />
You can either use directly CTest or the pyhton script created.<br />
<br />
===Using CTest===<br />
{|width = "100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer4-Superbuild/Slicer-build<br />
$ ctest -R MYTUTORIALNAME -VV<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer4-Superbuild\Slicer-build<br />
$ path\to\cmake\ctest.exe -R MYTUTORIALNAME -VV<br />
|}<br />
<br />
===Using the python script===<br />
{|width="100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer4/Application/SlicerApp/Testing/Python<br />
$ python MYTUTORIALNAME.py<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer4\Applicaiton\SlicerApp\Testing\Python<br />
$ path\to\Slicer4-Superbuild\python-build\PCBuild\python.exe MYTUTORIALNAME.py<br />
|}<br />
<br />
=Create custom translator/player=<br />
<br />
After created a custom widget, it might be possible that all its actions are not properly recorded, or played.<br><br />
QtTesting provides us basic translator and player template, to create our custom translator and player according to the widget. <br><br />
<br />
You can use the following command to create those basic files.<br />
<br />
{|width="100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer4-Superbuild/CTK-build/QtTesting/Utilities/Scripts<br />
$ python TranslatorPlayerWizard.py MY_WIDGET_NAME<br />
$ cd ../MY_WIDGET_NAME<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer4-Superbuild<br />
$ python-build\PCBuild\python.exe CTK-build\QtTesting\Utilities\Scripts\TranslatorPlayerWizard.py MY_WIDGET_NAME<br />
$ cd ../MY_WIDGET_NAME<br />
|}<br />
<br />
{{ambox<br />
| type = <br />
| text = 4 files should have been created ! <br> <br />
<code>MY_WIDGET_NAMETranslator.cpp <br> <br />
MY_WIDGET_NAMETranslator.h <br> <br />
MY_WIDGET_NAMEPlayer.cpp <br> <br />
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.<br />
}}<br />
<br />
Finally move the 4 files to the same directory as your widget<br />
<br />
$ cd path/to/Slicer4-Superbuild/CTK-build/QtTesting/Utilities/MY_WIDGET_NAME<br />
$ mv MY_WIDGET_NAMETranslator.cpp MY_WIDGET_NAMETranslator.h MY_WIDGET_NAMEPlayer.cpp MY_WIDGET_NAMEPlayer.h Path/To/My/Widget/Directory<br />
<br />
or just a simple copy to the same directory as your widget<br />
<br />
$ cp MY_WIDGET_NAMETranslator.cpp MY_WIDGET_NAMETranslator.h MY_WIDGET_NAMEPlayer.cpp MY_WIDGET_NAMEPlayer.h Path/To/My/Widget/Directory<br />
<br />
=Open bugs=<br />
Work in progress, following the two bug trackers :<br />
<br />
[http://na-mic.org/Mantis/search.php?project_id=3&category=QtTesting&sticky_issues=off&sortby=last_updated&dir=DESC&hide_status_id=-2 Slicer issues]<br />
<br />
[https://github.com/commontk/CTK/issues?labels=Testing&milestone=&page=1&state=open QtTesting issues]</div>BenjaminLonghttps://www.slicer.org/w/index.php?title=Documentation/Nightly/Developers/QtTesting&diff=26604Documentation/Nightly/Developers/QtTesting2012-06-05T13:57:46Z<p>BenjaminLong: </p>
<hr />
<div>{|width="100%"<br />
|<br />
__TOC__<br />
|align="right"|<br />
[[Image: 3DSlicerQtTesting.png]]<br />
|}<br />
=Overview=<br />
<br />
QtTesting provides us a testing framework to test our application. It complements unit tests, by testing the application in its globality.<br />
<br />
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.<br><br />
<br />
=Rule for Developers=<br />
<br />
=Write a 3DSlicer test using QtTesting=<br />
<br />
QtTesting framework can also be use to create module test.<br> Use the description below, but instead of <code>Slicer4/Applications/SlicerApp/Testing</code> all the path start by <code>Slicer4/Path/To/The/Modules/Testing</code><br />
<br />
Following is the different step to create a test using QtTesting framework. <br />
<br />
== Create your XML script ==<br />
See [http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/SlicerApplication/QtTesting QtTesting user Wiki] to know how to create this xml script.<br><br />
'''Save the xml script to''' <code>Slicer4/Applications/SlicerApp/Data/Input/MYTUTORIALNAME.xml''</code><br><br />
{{ambox <br />
| type = content<br />
|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]<br><br />
[[Documentation/{{documentation/version}}/Modules/SampleData Sample Data]] module according to the current Slicer version<br />
}}<br />
<br />
== Create a Python script ==<br />
''This Python test will start 3DSlicer and run the previously recorded xml script''<br />
<br />
'''''Create a python file with the following lines'''''<br />
<br />
import os<br />
import slicer<br />
import ApplicationsSlicerAppData as data<br />
filepath = data.input + '/MYTUTORIALNAME.xml') ex : NeurosurgicalPlanningTutorial.xml<br />
testUtility = slicer.app.testingUtility()<br />
success = testUtility.playTests(filepath)<br />
if not success :<br />
raise Exception('Failed to finished properly the play back !')<br />
<br />
'''''Save to the directory ''''' <code>Slicer4/Applications/SlicerApp/Testing/Python/MYTUTORIALNAME.py </code><br />
<br />
== Add the test in CMake ==<br />
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.<br />
<br />
Edit the file <code>Slicer4/Applications/SlicerApp/Testing/Python/CMakeLists.txt</code><br><br />
Add your test at the end of the Slicer_USE_QTTESTING condition and add the name in the <code>set_tests_properties</code> function :<br />
<br />
if(Slicer_USE_QTTESTING)<br />
{ <br />
...<br />
slicer_add_python_test(<br />
SCRIPT MYTUTORIALNAME.py<br />
SLICER_ARGS --launcher-no-splash --qt-testing)<br />
set_tests_properties(<br />
py_NeurosurgicalPlanningTutorial<br />
py_DiffusionTensorImagingTutorial<br />
....<br />
py_MYTUTORIALNAME<br />
...<br />
PROPERTIES RUN_SERIAL ON<br />
)<br />
}<br />
<br />
<br />
You just wrote a Slicer Unit Test using QtTesting framework !<br />
<br />
== Run your test==<br />
<br />
You can either use directly CTest or the pyhton script created.<br />
<br />
===Using CTest===<br />
{|width = "100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer4-Superbuild/Slicer-build<br />
$ ctest -R MYTUTORIALNAME -VV<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer4-Superbuild\Slicer-build<br />
$ path\to\cmake\ctest.exe -R MYTUTORIALNAME -VV<br />
|}<br />
<br />
===Using the python script===<br />
{|width="100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer4/Application/SlicerApp/Testing/Python<br />
$ python MYTUTORIALNAME.py<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer4\Applicaiton\SlicerApp\Testing\Python<br />
$ path\to\Slicer4-Superbuild\python-build\PCBuild\python.exe MYTUTORIALNAME.py<br />
|}<br />
<br />
=Create custom translator/player=<br />
<br />
After created a custom widget, it might be possible that all its actions are not properly recorded, or played.<br><br />
QtTesting provides us basic translator and player template, to create our custom translator and player according to the widget. <br><br />
<br />
You can use the following command to create those basic files.<br />
<br />
{|width="100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer4-Superbuild/CTK-build/QtTesting/Utilities/Scripts<br />
$ python TranslatorPlayerWizard.py MY_WIDGET_NAME<br />
$ cd ../MY_WIDGET_NAME<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer4-Superbuild<br />
$ python-build\PCBuild\python.exe CTK-build\QtTesting\Utilities\Scripts\TranslatorPlayerWizard.py MY_WIDGET_NAME<br />
$ cd ../MY_WIDGET_NAME<br />
|}<br />
<br />
{{ambox<br />
| type = <br />
| text = 4 files should have been created ! <br> <br />
<code>MY_WIDGET_NAMETranslator.cpp <br> <br />
MY_WIDGET_NAMETranslator.h <br> <br />
MY_WIDGET_NAMEPlayer.cpp <br> <br />
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.<br />
}}<br />
<br />
Finally move the 4 files to the same directory as your widget<br />
<br />
$ cd path/to/Slicer4-Superbuild/CTK-build/QtTesting/Utilities/MY_WIDGET_NAME<br />
$ mv MY_WIDGET_NAMETranslator.cpp MY_WIDGET_NAMETranslator.h MY_WIDGET_NAMEPlayer.cpp MY_WIDGET_NAMEPlayer.h Path/To/My/Widget/Directory<br />
<br />
or just a simple copy to the same directory as your widget<br />
<br />
$ cp MY_WIDGET_NAMETranslator.cpp MY_WIDGET_NAMETranslator.h MY_WIDGET_NAMEPlayer.cpp MY_WIDGET_NAMEPlayer.h Path/To/My/Widget/Directory<br />
<br />
=Open bugs=<br />
Work in progress, following the two bug trackers :<br />
<br />
[http://na-mic.org/Mantis/search.php?project_id=3&category=QtTesting&sticky_issues=off&sortby=last_updated&dir=DESC&hide_status_id=-2 Slicer issues]<br />
<br />
[https://github.com/commontk/CTK/issues?labels=Testing&milestone=&page=1&state=open QtTesting issues]</div>BenjaminLonghttps://www.slicer.org/w/index.php?title=Documentation/Nightly/SlicerApplication/QtTesting&diff=26603Documentation/Nightly/SlicerApplication/QtTesting2012-06-05T13:49:20Z<p>BenjaminLong: /* Overview */</p>
<hr />
<div>{|width="100%"<br />
|<br />
__TOC__<br />
|align="right"|<br />
[[Image: 3DSlicerQtTesting.png]]<br />
|}<br />
=Overview=<br />
<br />
Too lazy to do the same actions over and over? QtTesting is the answer! The QtTesting library provides you with an easy way to record and play macros with 3DSlicer. Included in this library is a user-friendly recording interface that shows you what actions you're recording as well as a simple and smart playback interface that will allow you to control actions whenever you want. With no input from the user, QtTesting record all accomplished actions from the point you have started the record until you stop it! "Create a puppet and let it do the rest ... "<br />
<br />
Slicer developers use this library to record tutorials and test the 3D Slicer application. How to create you own [http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/QtTesting QtTesting test]. <br><br />
<br />
<br />
[[Image: QtTestingMenu.png]]<br />
<br />
{{ambox <br />
| text = ''QtTesting is an effort started by the [http://paraview.org/Wiki/Testing_design ParaView team]'' <br />
}}<br />
<br />
==Activate QtTesting==<br />
<br />
{|width="100%"<br />
|valign="top"|<br />
By default, QtTesting is not activated. You must enable it to be able to record or play a saved macro.<br />
* Open the [[Documentation/{{documentation/version}}/SlicerApplication/ApplicationSettings|Application Settings]] dialog.<br />
* On the left side, select the ''QtTesting'' panel<br />
* Enable QtTesting by toggling the checkbox<br />
* Restart Slicer<br />
|align="right"|<br />
[[Image: QtTestingSettigns.png |450px]]<br />
|}<br />
<br />
<br />
==Recorder==<br />
Recording a macro consists in observing all the high level events (or low level in some cases) that the user generate by interacting with the GUI elements. All the events are saved into a file (.xml) that can be used later to [[#Player|replay]] the recorded events in the same or different instance of the Slicer application.<br />
{|width="100%"<br />
|<br />
=== Start recording ===<br />
* From the [[Documentation/{{documentation/version}}/SlicerApplication/MainApplicationGUI#Application_Menu|menu bar]], open the ''Edit'' menu and select the ''Record Macro'' item to start recording all your following events.<br />
''A record dialog appears at the bottom left of the application''<br />
<br />
=== Record dialog ===<br />
* Shows the last event recorded<br />
* Numbers of events recorded<br />
* ''You can stop the recording anytime by clicking on the Stop button''<br />
<br />
=== Save macro ===<br />
* When the recording is stopped, a dialog shows up to ask where to save the recorded macro file.<br />
<br />
|align="right"|<br />
[[Image: QtTestingRecorderDialog.jpg |300px]]<br />
|}<br />
<br />
<br />
==Player==<br />
Recorded macros (.xml) can be replayed within Slicer sessions. Note that the success of the macro execution can depend on the original state of the application.<br />
<br />
{|width="100%"<br />
|<br />
=== How to Start ===<br />
* From the [[Documentation/{{documentation/version}}/SlicerApplication/MainApplicationGUI#Application_Menu|menu bar]], open the ''Edit'' menu and select the ''Play Macro'' item to open the player dialog.<br />
<br />
=== Player dialog ===<br />
*'''Controller widget'''<br />
** Play, pause, stop or play-step-by-step your macro.<br />
** ''Logs'' check button shows/hides information about played events and errors if any.<br />
** ''Time step'' controls the playback speed by waiting Xms before playing each event.<br />
<br />
* '''Player tab''' (''default tab'')<br />
** Show the macro file played.<br />
<br />
* '''Info tab''' :<br />
** Show the last event played.<br />
<br />
===Default settings recorded===<br />
To limit playback problems, QtTesting records automatically some of the applications settings.<br />
* General settings :<br />
** The application's geometry<br />
** The application's state<br />
** The application's name<br />
** The application's version<br />
<br />
* 3DSlicer settings :<br />
** The current layout<br />
** The current module<br />
<br />
Before each play back, the application might have different current settings, QtTesting then asks if you want to restore the settings to the record application state. To maximize the chance of a successful playback, settings must be restored to set the application into a state as much as possible similar to when the macro was recorded.<br><br />
{{ambox<br />
| type = speedy<br />
| small = left<br />
| text = It's strongly recommended to accept !<br />
}}<br />
<br />
|align="right"|<br />
[[image: QtTestintPlayererDialog.jpg | 300px]]<br />
[[image: QtTestintRestoreSettingsDialog.png | 300px]]<br />
|}<br />
<br />
<br />
==User limitations==<br />
<br />
''QtTesting in 3DSlicer is still under heavy development, some events might not be recorded properly.''<br />
<br />
===What is subject to not work :===<br />
* Some actions under submenus, mainly actions on widget.<br />
<br />
===Work, but not perfectly:===<br />
* Shifts/offsets might happen when you recording events in the 3D views.</div>BenjaminLonghttps://www.slicer.org/w/index.php?title=Documentation/Nightly/Developers/QtTesting&diff=26602Documentation/Nightly/Developers/QtTesting2012-06-05T13:45:32Z<p>BenjaminLong: /* Create custom translator/player */</p>
<hr />
<div>{|width="100%"<br />
|<br />
__TOC__<br />
|align="right"|<br />
[[Image: 3DSlicerQtTesting.png]]<br />
|}<br />
=Overview=<br />
<br />
QtTesting provides us a testing framework to test our application. It complements unit tests, by testing the application in its globality.<br />
<br />
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.<br><br />
<br />
<br />
=Write a 3DSlicer test using QtTesting=<br />
<br />
QtTesting framework can also be use to create module test.<br> Use the description below, but instead of <code>Slicer4/Applications/SlicerApp/Testing</code> all the path start by <code>Slicer4/Path/To/The/Modules/Testing</code><br />
<br />
Following is the different step to create a test using QtTesting framework. <br />
<br />
== Create your XML script ==<br />
See [http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/SlicerApplication/QtTesting QtTesting user Wiki] to know how to create this xml script.<br><br />
'''Save the xml script to''' <code>Slicer4/Applications/SlicerApp/Data/Input/MYTUTORIALNAME.xml''</code><br><br />
{{ambox <br />
| type = content<br />
|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]<br><br />
[[Documentation/{{documentation/version}}/Modules/SampleData Sample Data]] module according to the current Slicer version<br />
}}<br />
<br />
== Create a Python script ==<br />
''This Python test will start 3DSlicer and run the previously recorded xml script''<br />
<br />
'''''Create a python file with the following lines'''''<br />
<br />
import os<br />
import slicer<br />
import ApplicationsSlicerAppData as data<br />
filepath = data.input + '/MYTUTORIALNAME.xml') ex : NeurosurgicalPlanningTutorial.xml<br />
testUtility = slicer.app.testingUtility()<br />
success = testUtility.playTests(filepath)<br />
if not success :<br />
raise Exception('Failed to finished properly the play back !')<br />
<br />
'''''Save to the directory ''''' <code>Slicer4/Applications/SlicerApp/Testing/Python/MYTUTORIALNAME.py </code><br />
<br />
== Add the test in CMake ==<br />
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.<br />
<br />
Edit the file <code>Slicer4/Applications/SlicerApp/Testing/Python/CMakeLists.txt</code><br><br />
Add your test at the end of the Slicer_USE_QTTESTING condition and add the name in the <code>set_tests_properties</code> function :<br />
<br />
if(Slicer_USE_QTTESTING)<br />
{ <br />
...<br />
slicer_add_python_test(<br />
SCRIPT MYTUTORIALNAME.py<br />
SLICER_ARGS --launcher-no-splash --qt-testing)<br />
set_tests_properties(<br />
py_NeurosurgicalPlanningTutorial<br />
py_DiffusionTensorImagingTutorial<br />
....<br />
py_MYTUTORIALNAME<br />
...<br />
PROPERTIES RUN_SERIAL ON<br />
)<br />
}<br />
<br />
<br />
You just wrote a Slicer Unit Test using QtTesting framework !<br />
<br />
== Run your test==<br />
<br />
You can either use directly CTest or the pyhton script created.<br />
<br />
===Using CTest===<br />
{|width = "100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer4-Superbuild/Slicer-build<br />
$ ctest -R MYTUTORIALNAME -VV<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer4-Superbuild\Slicer-build<br />
$ path\to\cmake\ctest.exe -R MYTUTORIALNAME -VV<br />
|}<br />
<br />
===Using the python script===<br />
{|width="100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer4/Application/SlicerApp/Testing/Python<br />
$ python MYTUTORIALNAME.py<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer4\Applicaiton\SlicerApp\Testing\Python<br />
$ path\to\Slicer4-Superbuild\python-build\PCBuild\python.exe MYTUTORIALNAME.py<br />
|}<br />
<br />
=Create custom translator/player=<br />
<br />
After created a custom widget, it might be possible that all its actions are not properly recorded, or played.<br><br />
QtTesting provides us basic translator and player template, to create our custom translator and player according to the widget. <br><br />
<br />
You can use the following command to create those basic files.<br />
<br />
{|width="100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer4-Superbuild/CTK-build/QtTesting/Utilities/Scripts<br />
$ python TranslatorPlayerWizard.py MY_WIDGET_NAME<br />
$ cd ../MY_WIDGET_NAME<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer4-Superbuild<br />
$ python-build\PCBuild\python.exe CTK-build\QtTesting\Utilities\Scripts\TranslatorPlayerWizard.py MY_WIDGET_NAME<br />
$ cd ../MY_WIDGET_NAME<br />
|}<br />
<br />
{{ambox<br />
| type = <br />
| text = 4 files should have been created ! <br> <br />
<code>MY_WIDGET_NAMETranslator.cpp <br> <br />
MY_WIDGET_NAMETranslator.h <br> <br />
MY_WIDGET_NAMEPlayer.cpp <br> <br />
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.<br />
}}<br />
<br />
Finally move the 4 files to the same directory as your widget<br />
<br />
$ cd path/to/Slicer4-Superbuild/CTK-build/QtTesting/Utilities/MY_WIDGET_NAME<br />
$ mv MY_WIDGET_NAMETranslator.cpp MY_WIDGET_NAMETranslator.h MY_WIDGET_NAMEPlayer.cpp MY_WIDGET_NAMEPlayer.h Path/To/My/Widget/Directory<br />
<br />
or just a simple copy to the same directory as your widget<br />
<br />
$ cp MY_WIDGET_NAMETranslator.cpp MY_WIDGET_NAMETranslator.h MY_WIDGET_NAMEPlayer.cpp MY_WIDGET_NAMEPlayer.h Path/To/My/Widget/Directory<br />
<br />
=Open bugs=<br />
Work in progress, following the two bug trackers :<br />
<br />
[http://na-mic.org/Mantis/search.php?project_id=3&category=QtTesting&sticky_issues=off&sortby=last_updated&dir=DESC&hide_status_id=-2 Slicer issues]<br />
<br />
[https://github.com/commontk/CTK/issues?labels=Testing&milestone=&page=1&state=open QtTesting issues]</div>BenjaminLonghttps://www.slicer.org/w/index.php?title=Documentation/Nightly/Developers/QtTesting&diff=26601Documentation/Nightly/Developers/QtTesting2012-06-05T13:43:42Z<p>BenjaminLong: /* Create custom translator/player */</p>
<hr />
<div>{|width="100%"<br />
|<br />
__TOC__<br />
|align="right"|<br />
[[Image: 3DSlicerQtTesting.png]]<br />
|}<br />
=Overview=<br />
<br />
QtTesting provides us a testing framework to test our application. It complements unit tests, by testing the application in its globality.<br />
<br />
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.<br><br />
<br />
<br />
=Write a 3DSlicer test using QtTesting=<br />
<br />
QtTesting framework can also be use to create module test.<br> Use the description below, but instead of <code>Slicer4/Applications/SlicerApp/Testing</code> all the path start by <code>Slicer4/Path/To/The/Modules/Testing</code><br />
<br />
Following is the different step to create a test using QtTesting framework. <br />
<br />
== Create your XML script ==<br />
See [http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/SlicerApplication/QtTesting QtTesting user Wiki] to know how to create this xml script.<br><br />
'''Save the xml script to''' <code>Slicer4/Applications/SlicerApp/Data/Input/MYTUTORIALNAME.xml''</code><br><br />
{{ambox <br />
| type = content<br />
|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]<br><br />
[[Documentation/{{documentation/version}}/Modules/SampleData Sample Data]] module according to the current Slicer version<br />
}}<br />
<br />
== Create a Python script ==<br />
''This Python test will start 3DSlicer and run the previously recorded xml script''<br />
<br />
'''''Create a python file with the following lines'''''<br />
<br />
import os<br />
import slicer<br />
import ApplicationsSlicerAppData as data<br />
filepath = data.input + '/MYTUTORIALNAME.xml') ex : NeurosurgicalPlanningTutorial.xml<br />
testUtility = slicer.app.testingUtility()<br />
success = testUtility.playTests(filepath)<br />
if not success :<br />
raise Exception('Failed to finished properly the play back !')<br />
<br />
'''''Save to the directory ''''' <code>Slicer4/Applications/SlicerApp/Testing/Python/MYTUTORIALNAME.py </code><br />
<br />
== Add the test in CMake ==<br />
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.<br />
<br />
Edit the file <code>Slicer4/Applications/SlicerApp/Testing/Python/CMakeLists.txt</code><br><br />
Add your test at the end of the Slicer_USE_QTTESTING condition and add the name in the <code>set_tests_properties</code> function :<br />
<br />
if(Slicer_USE_QTTESTING)<br />
{ <br />
...<br />
slicer_add_python_test(<br />
SCRIPT MYTUTORIALNAME.py<br />
SLICER_ARGS --launcher-no-splash --qt-testing)<br />
set_tests_properties(<br />
py_NeurosurgicalPlanningTutorial<br />
py_DiffusionTensorImagingTutorial<br />
....<br />
py_MYTUTORIALNAME<br />
...<br />
PROPERTIES RUN_SERIAL ON<br />
)<br />
}<br />
<br />
<br />
You just wrote a Slicer Unit Test using QtTesting framework !<br />
<br />
== Run your test==<br />
<br />
You can either use directly CTest or the pyhton script created.<br />
<br />
===Using CTest===<br />
{|width = "100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer4-Superbuild/Slicer-build<br />
$ ctest -R MYTUTORIALNAME -VV<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer4-Superbuild\Slicer-build<br />
$ path\to\cmake\ctest.exe -R MYTUTORIALNAME -VV<br />
|}<br />
<br />
===Using the python script===<br />
{|width="100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer4/Application/SlicerApp/Testing/Python<br />
$ python MYTUTORIALNAME.py<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer4\Applicaiton\SlicerApp\Testing\Python<br />
$ path\to\Slicer4-Superbuild\python-build\PCBuild\python.exe MYTUTORIALNAME.py<br />
|}<br />
<br />
=Create custom translator/player=<br />
<br />
After created a custom widget, it might be possible that all its actions are not properly recorded, or played.<br><br />
QtTesting provides us basic translator and player template, to create our custom translator and player according to the widget. <br><br />
<br />
You can use the following command to create those basic files.<br />
<br />
{|width="100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer4-Superbuild/CTK-build/QtTesting/Utilities/Scripts<br />
$ python TranslatorPlayerWizard.py MY_WIDGET_NAME<br />
$ cd ../MY_WIDGET_NAME<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer4-Superbuild<br />
$ python-build\PCBuild\python.exe CTK-build\QtTesting\Utilities\Scripts\TranslatorPlayerWizard.py MY_WIDGET_NAME<br />
$ cd ../MY_WIDGET_NAME<br />
|}<br />
<br />
{{ambox<br />
| type = <br />
| text = 4 files should have been created ! <br> <br />
<code>MY_WIDGET_NAMETranslator.cpp <br> <br />
MY_WIDGET_NAMETranslator.h <br> <br />
MY_WIDGET_NAMEPlayer.cpp <br> <br />
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.<br />
}}<br />
<br />
Finally move the 4 files to the same directory as your widget<br />
<br />
$ cd path/to/Slicer4-Superbuild/CTK-build/QtTesting/Utilities/MY_WIDGET_NAME<br />
$ mv MY_WIDGET_NAMETranslator.cpp MY_WIDGET_NAMETranslator.h MY_WIDGET_NAMEPlayer.cpp MY_WIDGET_NAMEPlayer.h Path/To/My/Widget/Directory<br />
<br />
=Open bugs=<br />
Work in progress, following the two bug trackers :<br />
<br />
[http://na-mic.org/Mantis/search.php?project_id=3&category=QtTesting&sticky_issues=off&sortby=last_updated&dir=DESC&hide_status_id=-2 Slicer issues]<br />
<br />
[https://github.com/commontk/CTK/issues?labels=Testing&milestone=&page=1&state=open QtTesting issues]</div>BenjaminLonghttps://www.slicer.org/w/index.php?title=Documentation/Nightly/Developers/QtTesting&diff=26600Documentation/Nightly/Developers/QtTesting2012-06-05T13:33:06Z<p>BenjaminLong: /* Create your XML script */</p>
<hr />
<div>{|width="100%"<br />
|<br />
__TOC__<br />
|align="right"|<br />
[[Image: 3DSlicerQtTesting.png]]<br />
|}<br />
=Overview=<br />
<br />
QtTesting provides us a testing framework to test our application. It complements unit tests, by testing the application in its globality.<br />
<br />
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.<br><br />
<br />
<br />
=Write a 3DSlicer test using QtTesting=<br />
<br />
QtTesting framework can also be use to create module test.<br> Use the description below, but instead of <code>Slicer4/Applications/SlicerApp/Testing</code> all the path start by <code>Slicer4/Path/To/The/Modules/Testing</code><br />
<br />
Following is the different step to create a test using QtTesting framework. <br />
<br />
== Create your XML script ==<br />
See [http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/SlicerApplication/QtTesting QtTesting user Wiki] to know how to create this xml script.<br><br />
'''Save the xml script to''' <code>Slicer4/Applications/SlicerApp/Data/Input/MYTUTORIALNAME.xml''</code><br><br />
{{ambox <br />
| type = content<br />
|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]<br><br />
[[Documentation/{{documentation/version}}/Modules/SampleData Sample Data]] module according to the current Slicer version<br />
}}<br />
<br />
== Create a Python script ==<br />
''This Python test will start 3DSlicer and run the previously recorded xml script''<br />
<br />
'''''Create a python file with the following lines'''''<br />
<br />
import os<br />
import slicer<br />
import ApplicationsSlicerAppData as data<br />
filepath = data.input + '/MYTUTORIALNAME.xml') ex : NeurosurgicalPlanningTutorial.xml<br />
testUtility = slicer.app.testingUtility()<br />
success = testUtility.playTests(filepath)<br />
if not success :<br />
raise Exception('Failed to finished properly the play back !')<br />
<br />
'''''Save to the directory ''''' <code>Slicer4/Applications/SlicerApp/Testing/Python/MYTUTORIALNAME.py </code><br />
<br />
== Add the test in CMake ==<br />
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.<br />
<br />
Edit the file <code>Slicer4/Applications/SlicerApp/Testing/Python/CMakeLists.txt</code><br><br />
Add your test at the end of the Slicer_USE_QTTESTING condition and add the name in the <code>set_tests_properties</code> function :<br />
<br />
if(Slicer_USE_QTTESTING)<br />
{ <br />
...<br />
slicer_add_python_test(<br />
SCRIPT MYTUTORIALNAME.py<br />
SLICER_ARGS --launcher-no-splash --qt-testing)<br />
set_tests_properties(<br />
py_NeurosurgicalPlanningTutorial<br />
py_DiffusionTensorImagingTutorial<br />
....<br />
py_MYTUTORIALNAME<br />
...<br />
PROPERTIES RUN_SERIAL ON<br />
)<br />
}<br />
<br />
<br />
You just wrote a Slicer Unit Test using QtTesting framework !<br />
<br />
== Run your test==<br />
<br />
You can either use directly CTest or the pyhton script created.<br />
<br />
===Using CTest===<br />
{|width = "100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer4-Superbuild/Slicer-build<br />
$ ctest -R MYTUTORIALNAME -VV<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer4-Superbuild\Slicer-build<br />
$ path\to\cmake\ctest.exe -R MYTUTORIALNAME -VV<br />
|}<br />
<br />
===Using the python script===<br />
{|width="100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer4/Application/SlicerApp/Testing/Python<br />
$ python MYTUTORIALNAME.py<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer4\Applicaiton\SlicerApp\Testing\Python<br />
$ path\to\Slicer4-Superbuild\python-build\PCBuild\python.exe MYTUTORIALNAME.py<br />
|}<br />
<br />
=Create custom translator/player=<br />
<br />
After created a custom widget, it might be possible that all its actions are not properly recorded, or played.<br><br />
QtTesting provides us basic translator and player template, to create our custom translator and player according to the widget. <br><br />
<br />
You can use the following command to create those basic files.<br />
<br />
{|width="100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer4-Superbuild/CTK-build/QtTesting/Utilities/Scripts<br />
$ python TranslatorPlayerWizard.py MY_WIDGET_NAME<br />
$ cd ../MY_WIDGET_NAME<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer4-Superbuild<br />
$ python-build\PCBuild\python.exe CTK-build\QtTesting\Utilities\Scripts\TranslatorPlayerWizard.py MY_WIDGET_NAME<br />
$ cd ../MY_WIDGET_NAME<br />
|}<br />
<br />
{{ambox<br />
| type = <br />
| text = 4 files should have been created ! <br> <br />
<code>MY_WIDGET_NAMETranslator.cpp <br> <br />
MY_WIDGET_NAMETranslator.h <br> <br />
MY_WIDGET_NAMEPlayer.cpp <br> <br />
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.<br />
}}<br />
<br />
=Open bugs=<br />
Work in progress, following the two bug trackers :<br />
<br />
[http://na-mic.org/Mantis/search.php?project_id=3&category=QtTesting&sticky_issues=off&sortby=last_updated&dir=DESC&hide_status_id=-2 Slicer issues]<br />
<br />
[https://github.com/commontk/CTK/issues?labels=Testing&milestone=&page=1&state=open QtTesting issues]</div>BenjaminLonghttps://www.slicer.org/w/index.php?title=Documentation/Nightly/Developers/QtTesting&diff=26599Documentation/Nightly/Developers/QtTesting2012-06-05T13:32:10Z<p>BenjaminLong: /* Using the python script */</p>
<hr />
<div>{|width="100%"<br />
|<br />
__TOC__<br />
|align="right"|<br />
[[Image: 3DSlicerQtTesting.png]]<br />
|}<br />
=Overview=<br />
<br />
QtTesting provides us a testing framework to test our application. It complements unit tests, by testing the application in its globality.<br />
<br />
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.<br><br />
<br />
<br />
=Write a 3DSlicer test using QtTesting=<br />
<br />
QtTesting framework can also be use to create module test.<br> Use the description below, but instead of <code>Slicer4/Applications/SlicerApp/Testing</code> all the path start by <code>Slicer4/Path/To/The/Modules/Testing</code><br />
<br />
Following is the different step to create a test using QtTesting framework. <br />
<br />
== Create your XML script ==<br />
See [http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/SlicerApplication/QtTesting QtTesting user Wiki] to know how to create this xml script.<br><br />
'''Save the xml script to''' <code>Slicer4/Applications/SlicerApp/Data/Input/MY_TUTORIAL_NAME_tutorial.xml''</code><br><br />
{{ambox <br />
| type = content<br />
|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]<br><br />
[[Documentation/{{documentation/version}}/Modules/SampleData Sample Data]] module according to the current Slicer version<br />
}}<br />
<br />
== Create a Python script ==<br />
''This Python test will start 3DSlicer and run the previously recorded xml script''<br />
<br />
'''''Create a python file with the following lines'''''<br />
<br />
import os<br />
import slicer<br />
import ApplicationsSlicerAppData as data<br />
filepath = data.input + '/MYTUTORIALNAME.xml') ex : NeurosurgicalPlanningTutorial.xml<br />
testUtility = slicer.app.testingUtility()<br />
success = testUtility.playTests(filepath)<br />
if not success :<br />
raise Exception('Failed to finished properly the play back !')<br />
<br />
'''''Save to the directory ''''' <code>Slicer4/Applications/SlicerApp/Testing/Python/MYTUTORIALNAME.py </code><br />
<br />
== Add the test in CMake ==<br />
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.<br />
<br />
Edit the file <code>Slicer4/Applications/SlicerApp/Testing/Python/CMakeLists.txt</code><br><br />
Add your test at the end of the Slicer_USE_QTTESTING condition and add the name in the <code>set_tests_properties</code> function :<br />
<br />
if(Slicer_USE_QTTESTING)<br />
{ <br />
...<br />
slicer_add_python_test(<br />
SCRIPT MYTUTORIALNAME.py<br />
SLICER_ARGS --launcher-no-splash --qt-testing)<br />
set_tests_properties(<br />
py_NeurosurgicalPlanningTutorial<br />
py_DiffusionTensorImagingTutorial<br />
....<br />
py_MYTUTORIALNAME<br />
...<br />
PROPERTIES RUN_SERIAL ON<br />
)<br />
}<br />
<br />
<br />
You just wrote a Slicer Unit Test using QtTesting framework !<br />
<br />
== Run your test==<br />
<br />
You can either use directly CTest or the pyhton script created.<br />
<br />
===Using CTest===<br />
{|width = "100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer4-Superbuild/Slicer-build<br />
$ ctest -R MYTUTORIALNAME -VV<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer4-Superbuild\Slicer-build<br />
$ path\to\cmake\ctest.exe -R MYTUTORIALNAME -VV<br />
|}<br />
<br />
===Using the python script===<br />
{|width="100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer4/Application/SlicerApp/Testing/Python<br />
$ python MYTUTORIALNAME.py<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer4\Applicaiton\SlicerApp\Testing\Python<br />
$ path\to\Slicer4-Superbuild\python-build\PCBuild\python.exe MYTUTORIALNAME.py<br />
|}<br />
<br />
=Create custom translator/player=<br />
<br />
After created a custom widget, it might be possible that all its actions are not properly recorded, or played.<br><br />
QtTesting provides us basic translator and player template, to create our custom translator and player according to the widget. <br><br />
<br />
You can use the following command to create those basic files.<br />
<br />
{|width="100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer4-Superbuild/CTK-build/QtTesting/Utilities/Scripts<br />
$ python TranslatorPlayerWizard.py MY_WIDGET_NAME<br />
$ cd ../MY_WIDGET_NAME<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer4-Superbuild<br />
$ python-build\PCBuild\python.exe CTK-build\QtTesting\Utilities\Scripts\TranslatorPlayerWizard.py MY_WIDGET_NAME<br />
$ cd ../MY_WIDGET_NAME<br />
|}<br />
<br />
{{ambox<br />
| type = <br />
| text = 4 files should have been created ! <br> <br />
<code>MY_WIDGET_NAMETranslator.cpp <br> <br />
MY_WIDGET_NAMETranslator.h <br> <br />
MY_WIDGET_NAMEPlayer.cpp <br> <br />
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.<br />
}}<br />
<br />
=Open bugs=<br />
Work in progress, following the two bug trackers :<br />
<br />
[http://na-mic.org/Mantis/search.php?project_id=3&category=QtTesting&sticky_issues=off&sortby=last_updated&dir=DESC&hide_status_id=-2 Slicer issues]<br />
<br />
[https://github.com/commontk/CTK/issues?labels=Testing&milestone=&page=1&state=open QtTesting issues]</div>BenjaminLonghttps://www.slicer.org/w/index.php?title=Documentation/Nightly/Developers/QtTesting&diff=26598Documentation/Nightly/Developers/QtTesting2012-06-05T13:31:47Z<p>BenjaminLong: /* Using CTest */</p>
<hr />
<div>{|width="100%"<br />
|<br />
__TOC__<br />
|align="right"|<br />
[[Image: 3DSlicerQtTesting.png]]<br />
|}<br />
=Overview=<br />
<br />
QtTesting provides us a testing framework to test our application. It complements unit tests, by testing the application in its globality.<br />
<br />
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.<br><br />
<br />
<br />
=Write a 3DSlicer test using QtTesting=<br />
<br />
QtTesting framework can also be use to create module test.<br> Use the description below, but instead of <code>Slicer4/Applications/SlicerApp/Testing</code> all the path start by <code>Slicer4/Path/To/The/Modules/Testing</code><br />
<br />
Following is the different step to create a test using QtTesting framework. <br />
<br />
== Create your XML script ==<br />
See [http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/SlicerApplication/QtTesting QtTesting user Wiki] to know how to create this xml script.<br><br />
'''Save the xml script to''' <code>Slicer4/Applications/SlicerApp/Data/Input/MY_TUTORIAL_NAME_tutorial.xml''</code><br><br />
{{ambox <br />
| type = content<br />
|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]<br><br />
[[Documentation/{{documentation/version}}/Modules/SampleData Sample Data]] module according to the current Slicer version<br />
}}<br />
<br />
== Create a Python script ==<br />
''This Python test will start 3DSlicer and run the previously recorded xml script''<br />
<br />
'''''Create a python file with the following lines'''''<br />
<br />
import os<br />
import slicer<br />
import ApplicationsSlicerAppData as data<br />
filepath = data.input + '/MYTUTORIALNAME.xml') ex : NeurosurgicalPlanningTutorial.xml<br />
testUtility = slicer.app.testingUtility()<br />
success = testUtility.playTests(filepath)<br />
if not success :<br />
raise Exception('Failed to finished properly the play back !')<br />
<br />
'''''Save to the directory ''''' <code>Slicer4/Applications/SlicerApp/Testing/Python/MYTUTORIALNAME.py </code><br />
<br />
== Add the test in CMake ==<br />
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.<br />
<br />
Edit the file <code>Slicer4/Applications/SlicerApp/Testing/Python/CMakeLists.txt</code><br><br />
Add your test at the end of the Slicer_USE_QTTESTING condition and add the name in the <code>set_tests_properties</code> function :<br />
<br />
if(Slicer_USE_QTTESTING)<br />
{ <br />
...<br />
slicer_add_python_test(<br />
SCRIPT MYTUTORIALNAME.py<br />
SLICER_ARGS --launcher-no-splash --qt-testing)<br />
set_tests_properties(<br />
py_NeurosurgicalPlanningTutorial<br />
py_DiffusionTensorImagingTutorial<br />
....<br />
py_MYTUTORIALNAME<br />
...<br />
PROPERTIES RUN_SERIAL ON<br />
)<br />
}<br />
<br />
<br />
You just wrote a Slicer Unit Test using QtTesting framework !<br />
<br />
== Run your test==<br />
<br />
You can either use directly CTest or the pyhton script created.<br />
<br />
===Using CTest===<br />
{|width = "100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer4-Superbuild/Slicer-build<br />
$ ctest -R MYTUTORIALNAME -VV<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer4-Superbuild\Slicer-build<br />
$ path\to\cmake\ctest.exe -R MYTUTORIALNAME -VV<br />
|}<br />
<br />
===Using the python script===<br />
{|width="100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer4/Application/SlicerApp/Testing/Python<br />
$ python MY_TEST_NAME.py<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer4\Applicaiton\SlicerApp\Testing\Python<br />
$ path\to\Slicer4-Superbuild\python-build\PCBuild\python.exe MY_TEST_NAME.py<br />
|}<br />
<br />
=Create custom translator/player=<br />
<br />
After created a custom widget, it might be possible that all its actions are not properly recorded, or played.<br><br />
QtTesting provides us basic translator and player template, to create our custom translator and player according to the widget. <br><br />
<br />
You can use the following command to create those basic files.<br />
<br />
{|width="100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer4-Superbuild/CTK-build/QtTesting/Utilities/Scripts<br />
$ python TranslatorPlayerWizard.py MY_WIDGET_NAME<br />
$ cd ../MY_WIDGET_NAME<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer4-Superbuild<br />
$ python-build\PCBuild\python.exe CTK-build\QtTesting\Utilities\Scripts\TranslatorPlayerWizard.py MY_WIDGET_NAME<br />
$ cd ../MY_WIDGET_NAME<br />
|}<br />
<br />
{{ambox<br />
| type = <br />
| text = 4 files should have been created ! <br> <br />
<code>MY_WIDGET_NAMETranslator.cpp <br> <br />
MY_WIDGET_NAMETranslator.h <br> <br />
MY_WIDGET_NAMEPlayer.cpp <br> <br />
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.<br />
}}<br />
<br />
=Open bugs=<br />
Work in progress, following the two bug trackers :<br />
<br />
[http://na-mic.org/Mantis/search.php?project_id=3&category=QtTesting&sticky_issues=off&sortby=last_updated&dir=DESC&hide_status_id=-2 Slicer issues]<br />
<br />
[https://github.com/commontk/CTK/issues?labels=Testing&milestone=&page=1&state=open QtTesting issues]</div>BenjaminLonghttps://www.slicer.org/w/index.php?title=Documentation/Nightly/Developers/QtTesting&diff=26597Documentation/Nightly/Developers/QtTesting2012-06-05T13:31:04Z<p>BenjaminLong: /* Add the test in CMake */</p>
<hr />
<div>{|width="100%"<br />
|<br />
__TOC__<br />
|align="right"|<br />
[[Image: 3DSlicerQtTesting.png]]<br />
|}<br />
=Overview=<br />
<br />
QtTesting provides us a testing framework to test our application. It complements unit tests, by testing the application in its globality.<br />
<br />
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.<br><br />
<br />
<br />
=Write a 3DSlicer test using QtTesting=<br />
<br />
QtTesting framework can also be use to create module test.<br> Use the description below, but instead of <code>Slicer4/Applications/SlicerApp/Testing</code> all the path start by <code>Slicer4/Path/To/The/Modules/Testing</code><br />
<br />
Following is the different step to create a test using QtTesting framework. <br />
<br />
== Create your XML script ==<br />
See [http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/SlicerApplication/QtTesting QtTesting user Wiki] to know how to create this xml script.<br><br />
'''Save the xml script to''' <code>Slicer4/Applications/SlicerApp/Data/Input/MY_TUTORIAL_NAME_tutorial.xml''</code><br><br />
{{ambox <br />
| type = content<br />
|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]<br><br />
[[Documentation/{{documentation/version}}/Modules/SampleData Sample Data]] module according to the current Slicer version<br />
}}<br />
<br />
== Create a Python script ==<br />
''This Python test will start 3DSlicer and run the previously recorded xml script''<br />
<br />
'''''Create a python file with the following lines'''''<br />
<br />
import os<br />
import slicer<br />
import ApplicationsSlicerAppData as data<br />
filepath = data.input + '/MYTUTORIALNAME.xml') ex : NeurosurgicalPlanningTutorial.xml<br />
testUtility = slicer.app.testingUtility()<br />
success = testUtility.playTests(filepath)<br />
if not success :<br />
raise Exception('Failed to finished properly the play back !')<br />
<br />
'''''Save to the directory ''''' <code>Slicer4/Applications/SlicerApp/Testing/Python/MYTUTORIALNAME.py </code><br />
<br />
== Add the test in CMake ==<br />
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.<br />
<br />
Edit the file <code>Slicer4/Applications/SlicerApp/Testing/Python/CMakeLists.txt</code><br><br />
Add your test at the end of the Slicer_USE_QTTESTING condition and add the name in the <code>set_tests_properties</code> function :<br />
<br />
if(Slicer_USE_QTTESTING)<br />
{ <br />
...<br />
slicer_add_python_test(<br />
SCRIPT MYTUTORIALNAME.py<br />
SLICER_ARGS --launcher-no-splash --qt-testing)<br />
set_tests_properties(<br />
py_NeurosurgicalPlanningTutorial<br />
py_DiffusionTensorImagingTutorial<br />
....<br />
py_MYTUTORIALNAME<br />
...<br />
PROPERTIES RUN_SERIAL ON<br />
)<br />
}<br />
<br />
<br />
You just wrote a Slicer Unit Test using QtTesting framework !<br />
<br />
== Run your test==<br />
<br />
You can either use directly CTest or the pyhton script created.<br />
<br />
===Using CTest===<br />
{|width = "100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer4-Superbuild/Slicer-build<br />
$ ctest -R MY_TEST_NAME -VV<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer4-Superbuild\Slicer-build<br />
$ path\to\cmake\ctest.exe -R MY_TEST_NAME -VV<br />
|}<br />
<br />
===Using the python script===<br />
{|width="100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer4/Application/SlicerApp/Testing/Python<br />
$ python MY_TEST_NAME.py<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer4\Applicaiton\SlicerApp\Testing\Python<br />
$ path\to\Slicer4-Superbuild\python-build\PCBuild\python.exe MY_TEST_NAME.py<br />
|}<br />
<br />
=Create custom translator/player=<br />
<br />
After created a custom widget, it might be possible that all its actions are not properly recorded, or played.<br><br />
QtTesting provides us basic translator and player template, to create our custom translator and player according to the widget. <br><br />
<br />
You can use the following command to create those basic files.<br />
<br />
{|width="100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer4-Superbuild/CTK-build/QtTesting/Utilities/Scripts<br />
$ python TranslatorPlayerWizard.py MY_WIDGET_NAME<br />
$ cd ../MY_WIDGET_NAME<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer4-Superbuild<br />
$ python-build\PCBuild\python.exe CTK-build\QtTesting\Utilities\Scripts\TranslatorPlayerWizard.py MY_WIDGET_NAME<br />
$ cd ../MY_WIDGET_NAME<br />
|}<br />
<br />
{{ambox<br />
| type = <br />
| text = 4 files should have been created ! <br> <br />
<code>MY_WIDGET_NAMETranslator.cpp <br> <br />
MY_WIDGET_NAMETranslator.h <br> <br />
MY_WIDGET_NAMEPlayer.cpp <br> <br />
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.<br />
}}<br />
<br />
=Open bugs=<br />
Work in progress, following the two bug trackers :<br />
<br />
[http://na-mic.org/Mantis/search.php?project_id=3&category=QtTesting&sticky_issues=off&sortby=last_updated&dir=DESC&hide_status_id=-2 Slicer issues]<br />
<br />
[https://github.com/commontk/CTK/issues?labels=Testing&milestone=&page=1&state=open QtTesting issues]</div>BenjaminLonghttps://www.slicer.org/w/index.php?title=Documentation/Nightly/Developers/QtTesting&diff=26596Documentation/Nightly/Developers/QtTesting2012-06-05T13:29:56Z<p>BenjaminLong: /* Create a Python script */</p>
<hr />
<div>{|width="100%"<br />
|<br />
__TOC__<br />
|align="right"|<br />
[[Image: 3DSlicerQtTesting.png]]<br />
|}<br />
=Overview=<br />
<br />
QtTesting provides us a testing framework to test our application. It complements unit tests, by testing the application in its globality.<br />
<br />
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.<br><br />
<br />
<br />
=Write a 3DSlicer test using QtTesting=<br />
<br />
QtTesting framework can also be use to create module test.<br> Use the description below, but instead of <code>Slicer4/Applications/SlicerApp/Testing</code> all the path start by <code>Slicer4/Path/To/The/Modules/Testing</code><br />
<br />
Following is the different step to create a test using QtTesting framework. <br />
<br />
== Create your XML script ==<br />
See [http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/SlicerApplication/QtTesting QtTesting user Wiki] to know how to create this xml script.<br><br />
'''Save the xml script to''' <code>Slicer4/Applications/SlicerApp/Data/Input/MY_TUTORIAL_NAME_tutorial.xml''</code><br><br />
{{ambox <br />
| type = content<br />
|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]<br><br />
[[Documentation/{{documentation/version}}/Modules/SampleData Sample Data]] module according to the current Slicer version<br />
}}<br />
<br />
== Create a Python script ==<br />
''This Python test will start 3DSlicer and run the previously recorded xml script''<br />
<br />
'''''Create a python file with the following lines'''''<br />
<br />
import os<br />
import slicer<br />
import ApplicationsSlicerAppData as data<br />
filepath = data.input + '/MYTUTORIALNAME.xml') ex : NeurosurgicalPlanningTutorial.xml<br />
testUtility = slicer.app.testingUtility()<br />
success = testUtility.playTests(filepath)<br />
if not success :<br />
raise Exception('Failed to finished properly the play back !')<br />
<br />
'''''Save to the directory ''''' <code>Slicer4/Applications/SlicerApp/Testing/Python/MYTUTORIALNAME.py </code><br />
<br />
== Add the test in CMake ==<br />
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.<br />
<br />
Edit the file <code>Slicer4/Applications/SlicerApp/Testing/Python/CMakeLists.txt</code><br><br />
Add your test at the end of the Slicer_USE_QTTESTING condition and add the name in the <code>set_tests_properties</code> function :<br />
<br />
if(Slicer_USE_QTTESTING)<br />
{ <br />
...<br />
slicer_add_python_test(<br />
SCRIPT pythonScriptName.py<br />
SLICER_ARGS --launcher-no-splash --qt-testing)<br />
set_tests_properties(<br />
py_Slicer_NeurosurgicalPlanning-Tutorial<br />
py_Slicer_DiffusionTensorImaging-Tutorial<br />
....<br />
py_Slicer_YOUR_TUTORIAL_NAME<br />
...<br />
PROPERTIES RUN_SERIAL ON<br />
)<br />
}<br />
<br />
<br />
You just wrote a Slicer Unit Test using QtTesting framework !<br />
<br />
== Run your test==<br />
<br />
You can either use directly CTest or the pyhton script created.<br />
<br />
===Using CTest===<br />
{|width = "100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer4-Superbuild/Slicer-build<br />
$ ctest -R MY_TEST_NAME -VV<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer4-Superbuild\Slicer-build<br />
$ path\to\cmake\ctest.exe -R MY_TEST_NAME -VV<br />
|}<br />
<br />
===Using the python script===<br />
{|width="100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer4/Application/SlicerApp/Testing/Python<br />
$ python MY_TEST_NAME.py<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer4\Applicaiton\SlicerApp\Testing\Python<br />
$ path\to\Slicer4-Superbuild\python-build\PCBuild\python.exe MY_TEST_NAME.py<br />
|}<br />
<br />
=Create custom translator/player=<br />
<br />
After created a custom widget, it might be possible that all its actions are not properly recorded, or played.<br><br />
QtTesting provides us basic translator and player template, to create our custom translator and player according to the widget. <br><br />
<br />
You can use the following command to create those basic files.<br />
<br />
{|width="100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer4-Superbuild/CTK-build/QtTesting/Utilities/Scripts<br />
$ python TranslatorPlayerWizard.py MY_WIDGET_NAME<br />
$ cd ../MY_WIDGET_NAME<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer4-Superbuild<br />
$ python-build\PCBuild\python.exe CTK-build\QtTesting\Utilities\Scripts\TranslatorPlayerWizard.py MY_WIDGET_NAME<br />
$ cd ../MY_WIDGET_NAME<br />
|}<br />
<br />
{{ambox<br />
| type = <br />
| text = 4 files should have been created ! <br> <br />
<code>MY_WIDGET_NAMETranslator.cpp <br> <br />
MY_WIDGET_NAMETranslator.h <br> <br />
MY_WIDGET_NAMEPlayer.cpp <br> <br />
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.<br />
}}<br />
<br />
=Open bugs=<br />
Work in progress, following the two bug trackers :<br />
<br />
[http://na-mic.org/Mantis/search.php?project_id=3&category=QtTesting&sticky_issues=off&sortby=last_updated&dir=DESC&hide_status_id=-2 Slicer issues]<br />
<br />
[https://github.com/commontk/CTK/issues?labels=Testing&milestone=&page=1&state=open QtTesting issues]</div>BenjaminLonghttps://www.slicer.org/w/index.php?title=Documentation/4.1/Developers/Tutorials/Debug_Instructions&diff=26547Documentation/4.1/Developers/Tutorials/Debug Instructions2012-06-04T17:19:26Z<p>BenjaminLong: /* Analyze a segmentation fault */</p>
<hr />
<div>==Background==<br />
The executable Slicer application ''Slicer-Superbuild/Slicer-build/Slicer'' (or Slicer.exe) is the [[Documentation/{{documentation/version}}/Developers/Launcher|launcher]] of the real application binary ''Slicer-Superbuild/Slicer-build/bin/SlicerQT-real''.<br />
<br />
==Linux==<br />
===Analyze a segmentation fault===<br />
$ ulimit -c unlimited<br />
$ ./Slicer<br />
... make it crash<br />
$ ./Slicer --gdb ./bin/SlicerApp-real<br />
(gdb) core core<br />
(gdb) backtrace<br />
...<br />
<br />
===GDB debug with launch arguments===<br />
The Slicer app launcher provides options to start other programs with the Slicer environment settings. <br />
<br />
*<code>--launch <executable> [<parameters>]</code>: executes an arbitrary program. For example, <code>Slicer --launch /usr/bin/gnome-terminal</code> starts gnome-terminal (then run GDB directly on SlicerQT-real)<br />
*<code>--gdb</code>: runs GDB then executes SlicerQT-real from within the debugger environment.<br />
<br />
===GDB debug by attaching to running process [RECOMMENDED] ===<br />
<br />
1) Running Slicer with the following command line argument will allow you to easily obtain the associated PID:<br />
<br />
$ ./Slicer --attach-process<br />
<br />
This will bring up a window with the <code>PID</code> before loading any modules, which is also helpful for debugging the loading process.<br />
<br />
2) Then, you can attach the process to <code>gdb</code> using the following command:<br />
<br />
$ gdb --pid $PIDABOVE<br />
<br />
3) Finally type the following gdb command<br />
<br />
(gdb) continue<br />
<br />
If not using the <code>--attach-process</code>, the <code>PID</code> could be obtain using the following command:<br />
<br />
$ ps -Afww | grep SlicerApp-real<br />
<br />
<br />
==== Ubuntu 10.10 and above - How to enable ptracing ====<br />
In Ubuntu 10.10, Ubuntu introduced a patch to disallow ptracing of non-child processes by non-root users -ie. only a process which is a parent of another process can ptrace it for normal users.<br />
You can temporarily disable this restriction by:<br />
$ echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope<br />
To permanently allow it to edit /etc/sysctl.d/10-ptrace.conf and change the line:<br />
*<code>kernel.yama.ptrace_scope = 1</code><br />
to read:<br />
*<code>kernel.yama.ptrace_scope = 0</code><br />
<br />
See http://askubuntu.com/questions/41629/after-upgrade-gdb-wont-attach-to-process<br />
<br />
===GDB debug by using exec-wrapper===<br />
An alternative approach is to use a wrapper script to emulate the functionality of the app launcher. This will allow you to use gdb or a gdb-controlling program such as an IDE, in order to interactively debug directly from GDB without attaching.<br />
<br />
The general idea of the wrapper is to set all of the appropriate environment variables as they would be set by the app launcher. From SlicerLauncherSettings:<br />
*[LibraryPath] contents should be in LD_LIBRARY_PATH<br />
*[Paths] contents should be in PATH<br />
*[EnvironmentVariables] should each be set<br />
<br />
See [[Slicer4:Example_Wrapper_Script|this example script]]<br />
<br />
Now, start gdb and do the following:<br />
<pre><br />
(gdb) set exec-wrapper ./WrapSlicer4 <br />
(gdb) exec-file ./bin/SlicerQT-real<br />
(gdb) run<br />
</pre><br />
<br />
Since VTK and ITK include many multithreaded filters, by default you will see lots of messages like the following from gdb during rendering and processing:<br />
[New Thread 0x7fff8378f700 (LWP 20510)]<br />
[Thread 0x7fff8b0aa700 (LWP 20506) exited]<br />
<br />
These can be turned off with this command:<br />
set print thread-events off<br />
<br />
===GDB debug in CodeLite IDE===<br />
[[Slicer4:Linux_Debugging_CodeLite|Linux debugging with CodeLite IDE]]<br />
<br />
== Windows ==<br />
<br />
For VisualStudio it's also possible to run the IDE with the correct environment to debug slicer.<br />
<br />
The launcher gets configured with a special --VisualStudio option for this purpose. <br />
<br />
Note that because CMake re-creates the solution file from within the build process, visual studio will sometimes need to stop and reload the project, requiring manual button pressing on your part. To avoid this, you can use a script to kick off the build and then re-start the IDE.<br />
<br />
If you use cygwin, you can create simple shell scripts, for example in /usr/local/bin, which these several steps at once when run from the Slicer4-superbuild directory:<br />
<br />
* ''s4build'' (slicer4 build)<br />
(cd Slicer-build; cmake.exe -VV --debug-output . && ./Slicer.exe --VisualStudio Slicer.sln /out buildlog.txt /build)<br />
(cd Slicer-build; ./Slicer.exe --VisualStudio Slicer.sln)<br />
* ''s4sbuild'' (slicer4 super build)<br />
(cmake.exe -VV --debug-output . && ./Slicer-build/Slicer.exe --VisualStudio Slicer.sln /out buildlog.txt /build)<br />
(cd Slicer-build; ./Slicer.exe --VisualStudio Slicer.sln)<br />
<br />
The ''s4build'' command re-runs cmake and then runs the build of Slicer only. When this completes, it launches visual studio with slicer loaded for debugging.<br />
<br />
''s4sbuild'' is similar, but it runs the superbuild process so that all the dependency libraries are updated. This takes longer, but is sometimes needed when there has been a change to CTK or other tools.<br />
<br />
Note the buildlog.txt files for checking if anything went wrong.<br />
==Debugging a Test==<br />
Once VisualStudio is open with the Slicer environment loaded, it is possible to run and debug tests.<br />
To run all tests, build the ''RUN_TESTS'' project.<br />
#To debug a test, find its project:<br />
##Libs/MRML/Core tests are in the ''MRMLCoreCxxTests'' project<br />
##CLI tests are in ''CLI_NAMETest'' project (e.g. ThresholdScalarVolumeTest) <br />
##Loadable module tests are in ''qSlicerLOADABLE_NAMECxxTests'' project (e.g. qSlicerVolumeRenderingCxxTests) <br />
##Module logic tests are in ''MODULE_NAMELogicCxxTests'' project (e.g. VolumeRenderingLogicCxxTests) <br />
##Module widgets tests are in ''MODULE_NAMEWidgetsCxxTests'' project (e.g. VolumesWidgetsCxxTests)<br />
#Go to the project debugging properties (right click -> Properties, then Configuration Properties/Debugging)<br />
#In ''Command Arguments'', type the name of the test (e.g. <code>vtkMRMLSceneImportTest</code> for project MRMLCoreCxxTests)<br />
# If the test takes argument(s), enter the argument(s) after the test name in ''Command Arguments'' (e.g. <code>vtkMRMLSceneImportTest C:\Path\To\Slicer4\Libs\MRML\Core\Testing\vol_and_cube.mrml</code>)<br />
## You can see what arguments are passed by the dashboards by looking at the test details in [http://slicer.cdash.org/index.php?project=Slicer4 CDash].<br />
## Most VTK and Qt tests support the <code>-I</code> argument, it allows the test to be run in "interactive" mode. It doesn't exit at the end of the test.<br />
# Make the project ''Set As StartUp Project''<br />
# ''Start Debugging (F5)''</div>BenjaminLonghttps://www.slicer.org/w/index.php?title=Documentation/4.1/Developers/Tutorials/Debug_Instructions&diff=26540Documentation/4.1/Developers/Tutorials/Debug Instructions2012-06-04T15:49:55Z<p>BenjaminLong: /* GDB debug by attaching to running process [RECOMMENDED] */</p>
<hr />
<div>==Background==<br />
The executable Slicer application ''Slicer-Superbuild/Slicer-build/Slicer'' (or Slicer.exe) is the [[Documentation/{{documentation/version}}/Developers/Launcher|launcher]] of the real application binary ''Slicer-Superbuild/Slicer-build/bin/SlicerQT-real''.<br />
<br />
==Linux==<br />
===Analyze a segmentation fault===<br />
$ ulimit -c unlimited<br />
$ ./Slicer<br />
... make it crash<br />
$ ./Slicer --gdb ./bin/SlicerQT-real<br />
(gdb) core core<br />
(gdb) backtrace<br />
...<br />
===GDB debug with launch arguments===<br />
The Slicer app launcher provides options to start other programs with the Slicer environment settings. <br />
<br />
*<code>--launch <executable> [<parameters>]</code>: executes an arbitrary program. For example, <code>Slicer --launch /usr/bin/gnome-terminal</code> starts gnome-terminal (then run GDB directly on SlicerQT-real)<br />
*<code>--gdb</code>: runs GDB then executes SlicerQT-real from within the debugger environment.<br />
<br />
===GDB debug by attaching to running process [RECOMMENDED] ===<br />
<br />
1) Running Slicer with the following command line argument will allow you to easily obtain the associated PID:<br />
<br />
$ ./Slicer --attach-process<br />
<br />
This will bring up a window with the <code>PID</code> before loading any modules, which is also helpful for debugging the loading process.<br />
<br />
2) Then, you can attach the process to <code>gdb</code> using the following command:<br />
<br />
$ gdb --pid $PIDABOVE<br />
<br />
3) Finally type the following gdb command<br />
<br />
(gdb) continue<br />
<br />
If not using the <code>--attach-process</code>, the <code>PID</code> could be obtain using the following command:<br />
<br />
$ ps -Afww | grep SlicerApp-real<br />
<br />
<br />
==== Ubuntu 10.10 and above - How to enable ptracing ====<br />
In Ubuntu 10.10, Ubuntu introduced a patch to disallow ptracing of non-child processes by non-root users -ie. only a process which is a parent of another process can ptrace it for normal users.<br />
You can temporarily disable this restriction by:<br />
$ echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope<br />
To permanently allow it to edit /etc/sysctl.d/10-ptrace.conf and change the line:<br />
*<code>kernel.yama.ptrace_scope = 1</code><br />
to read:<br />
*<code>kernel.yama.ptrace_scope = 0</code><br />
<br />
See http://askubuntu.com/questions/41629/after-upgrade-gdb-wont-attach-to-process<br />
<br />
===GDB debug by using exec-wrapper===<br />
An alternative approach is to use a wrapper script to emulate the functionality of the app launcher. This will allow you to use gdb or a gdb-controlling program such as an IDE, in order to interactively debug directly from GDB without attaching.<br />
<br />
The general idea of the wrapper is to set all of the appropriate environment variables as they would be set by the app launcher. From SlicerLauncherSettings:<br />
*[LibraryPath] contents should be in LD_LIBRARY_PATH<br />
*[Paths] contents should be in PATH<br />
*[EnvironmentVariables] should each be set<br />
<br />
See [[Slicer4:Example_Wrapper_Script|this example script]]<br />
<br />
Now, start gdb and do the following:<br />
<pre><br />
(gdb) set exec-wrapper ./WrapSlicer4 <br />
(gdb) exec-file ./bin/SlicerQT-real<br />
(gdb) run<br />
</pre><br />
<br />
Since VTK and ITK include many multithreaded filters, by default you will see lots of messages like the following from gdb during rendering and processing:<br />
[New Thread 0x7fff8378f700 (LWP 20510)]<br />
[Thread 0x7fff8b0aa700 (LWP 20506) exited]<br />
<br />
These can be turned off with this command:<br />
set print thread-events off<br />
<br />
===GDB debug in CodeLite IDE===<br />
[[Slicer4:Linux_Debugging_CodeLite|Linux debugging with CodeLite IDE]]<br />
<br />
== Windows ==<br />
<br />
For VisualStudio it's also possible to run the IDE with the correct environment to debug slicer.<br />
<br />
The launcher gets configured with a special --VisualStudio option for this purpose. <br />
<br />
Note that because CMake re-creates the solution file from within the build process, visual studio will sometimes need to stop and reload the project, requiring manual button pressing on your part. To avoid this, you can use a script to kick off the build and then re-start the IDE.<br />
<br />
If you use cygwin, you can create simple shell scripts, for example in /usr/local/bin, which these several steps at once when run from the Slicer4-superbuild directory:<br />
<br />
* ''s4build'' (slicer4 build)<br />
(cd Slicer-build; cmake.exe -VV --debug-output . && ./Slicer.exe --VisualStudio Slicer.sln /out buildlog.txt /build)<br />
(cd Slicer-build; ./Slicer.exe --VisualStudio Slicer.sln)<br />
* ''s4sbuild'' (slicer4 super build)<br />
(cmake.exe -VV --debug-output . && ./Slicer-build/Slicer.exe --VisualStudio Slicer.sln /out buildlog.txt /build)<br />
(cd Slicer-build; ./Slicer.exe --VisualStudio Slicer.sln)<br />
<br />
The ''s4build'' command re-runs cmake and then runs the build of Slicer only. When this completes, it launches visual studio with slicer loaded for debugging.<br />
<br />
''s4sbuild'' is similar, but it runs the superbuild process so that all the dependency libraries are updated. This takes longer, but is sometimes needed when there has been a change to CTK or other tools.<br />
<br />
Note the buildlog.txt files for checking if anything went wrong.<br />
==Debugging a Test==<br />
Once VisualStudio is open with the Slicer environment loaded, it is possible to run and debug tests.<br />
To run all tests, build the ''RUN_TESTS'' project.<br />
#To debug a test, find its project:<br />
##Libs/MRML/Core tests are in the ''MRMLCoreCxxTests'' project<br />
##CLI tests are in ''CLI_NAMETest'' project (e.g. ThresholdScalarVolumeTest) <br />
##Loadable module tests are in ''qSlicerLOADABLE_NAMECxxTests'' project (e.g. qSlicerVolumeRenderingCxxTests) <br />
##Module logic tests are in ''MODULE_NAMELogicCxxTests'' project (e.g. VolumeRenderingLogicCxxTests) <br />
##Module widgets tests are in ''MODULE_NAMEWidgetsCxxTests'' project (e.g. VolumesWidgetsCxxTests)<br />
#Go to the project debugging properties (right click -> Properties, then Configuration Properties/Debugging)<br />
#In ''Command Arguments'', type the name of the test (e.g. <code>vtkMRMLSceneImportTest</code> for project MRMLCoreCxxTests)<br />
# If the test takes argument(s), enter the argument(s) after the test name in ''Command Arguments'' (e.g. <code>vtkMRMLSceneImportTest C:\Path\To\Slicer4\Libs\MRML\Core\Testing\vol_and_cube.mrml</code>)<br />
## You can see what arguments are passed by the dashboards by looking at the test details in [http://slicer.cdash.org/index.php?project=Slicer4 CDash].<br />
## Most VTK and Qt tests support the <code>-I</code> argument, it allows the test to be run in "interactive" mode. It doesn't exit at the end of the test.<br />
# Make the project ''Set As StartUp Project''<br />
# ''Start Debugging (F5)''</div>BenjaminLonghttps://www.slicer.org/w/index.php?title=Documentation/Nightly/SlicerApplication/QtTesting&diff=26493Documentation/Nightly/SlicerApplication/QtTesting2012-05-30T17:45:26Z<p>BenjaminLong: /* Overview */</p>
<hr />
<div>{|width="100%"<br />
|<br />
__TOC__<br />
|align="right"|<br />
[[Image: 3DSlicerQtTesting.png]]<br />
|}<br />
=Overview=<br />
<br />
Too lazy to do the same actions over and over? QtTesting is the answer! The QtTesting library provides you with an easy way to record and play macros with 3DSlicer. Included in this library is a user-friendly recording interface that shows you what actions you're recording as well as a simple and smart playback interface that will allow you to control actions whenever you want. With no input from the user, QtTesting record all accomplished actions from the point you have started the record until you stop it! "Create a puppet and let it do the rest ... "<br />
<br />
Slicer developers use this library to record tutorials and test the 3D Slicer application.[http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/QtTesting See] how to create you own QtTesting test.<br><br />
<br />
<br />
[[Image: QtTestingMenu.png]]<br />
<br />
{{ambox <br />
| text = ''QtTesting is an effort started by the [http://paraview.org/Wiki/Testing_design ParaView team]'' <br />
}}<br />
<br />
==Activate QtTesting==<br />
<br />
{|width="100%"<br />
|valign="top"|<br />
By default, QtTesting is not activated. You must enable it to be able to record or play a saved macro.<br />
* Open the [[Documentation/{{documentation/version}}/SlicerApplication/ApplicationSettings|Application Settings]] dialog.<br />
* On the left side, select the ''QtTesting'' panel<br />
* Enable QtTesting by toggling the checkbox<br />
* Restart Slicer<br />
|align="right"|<br />
[[Image: QtTestingSettigns.png |450px]]<br />
|}<br />
<br />
<br />
==Recorder==<br />
Recording a macro consists in observing all the high level events (or low level in some cases) that the user generate by interacting with the GUI elements. All the events are saved into a file (.xml) that can be used later to [[#Player|replay]] the recorded events in the same or different instance of the Slicer application.<br />
{|width="100%"<br />
|<br />
=== Start recording ===<br />
* From the [[Documentation/{{documentation/version}}/SlicerApplication/MainApplicationGUI#Application_Menu|menu bar]], open the ''Edit'' menu and select the ''Record Macro'' item to start recording all your following events.<br />
''A record dialog appears at the bottom left of the application''<br />
<br />
=== Record dialog ===<br />
* Shows the last event recorded<br />
* Numbers of events recorded<br />
* ''You can stop the recording anytime by clicking on the Stop button''<br />
<br />
=== Save macro ===<br />
* When the recording is stopped, a dialog shows up to ask where to save the recorded macro file.<br />
<br />
|align="right"|<br />
[[Image: QtTestingRecorderDialog.jpg |300px]]<br />
|}<br />
<br />
<br />
==Player==<br />
Recorded macros (.xml) can be replayed within Slicer sessions. Note that the success of the macro execution can depend on the original state of the application.<br />
<br />
{|width="100%"<br />
|<br />
=== How to Start ===<br />
* From the [[Documentation/{{documentation/version}}/SlicerApplication/MainApplicationGUI#Application_Menu|menu bar]], open the ''Edit'' menu and select the ''Play Macro'' item to open the player dialog.<br />
<br />
=== Player dialog ===<br />
*'''Controller widget'''<br />
** Play, pause, stop or play-step-by-step your macro.<br />
** ''Logs'' check button shows/hides information about played events and errors if any.<br />
** ''Time step'' controls the playback speed by waiting Xms before playing each event.<br />
<br />
* '''Player tab''' (''default tab'')<br />
** Show the macro file played.<br />
<br />
* '''Info tab''' :<br />
** Show the last event played.<br />
<br />
===Default settings recorded===<br />
To limit playback problems, QtTesting records automatically some of the applications settings.<br />
* General settings :<br />
** The application's geometry<br />
** The application's state<br />
** The application's name<br />
** The application's version<br />
<br />
* 3DSlicer settings :<br />
** The current layout<br />
** The current module<br />
<br />
Before each play back, the application might have different current settings, QtTesting then asks if you want to restore the settings to the record application state. To maximize the chance of a successful playback, settings must be restored to set the application into a state as much as possible similar to when the macro was recorded.<br><br />
{{ambox<br />
| type = speedy<br />
| small = left<br />
| text = It's strongly recommended to accept !<br />
}}<br />
<br />
|align="right"|<br />
[[image: QtTestintPlayererDialog.jpg | 300px]]<br />
[[image: QtTestintRestoreSettingsDialog.png | 300px]]<br />
|}<br />
<br />
<br />
==User limitations==<br />
<br />
''QtTesting in 3DSlicer is still under heavy development, some events might not be recorded properly.''<br />
<br />
===What is subject to not work :===<br />
* Some actions under submenus, mainly actions on widget.<br />
<br />
===Work, but not perfectly:===<br />
* Shifts/offsets might happen when you recording events in the 3D views.</div>BenjaminLonghttps://www.slicer.org/w/index.php?title=Documentation/Nightly/SlicerApplication/QtTesting&diff=26492Documentation/Nightly/SlicerApplication/QtTesting2012-05-30T17:41:13Z<p>BenjaminLong: /* User limitations */</p>
<hr />
<div>{|width="100%"<br />
|<br />
__TOC__<br />
|align="right"|<br />
[[Image: 3DSlicerQtTesting.png]]<br />
|}<br />
=Overview=<br />
<br />
Too lazy to do the same actions over and over? QtTesting is the answer! The QtTesting library provides you with an easy way to record and play macros with 3DSlicer. Included in this library is a user-friendly recording interface that shows you what actions you're recording as well as a simple and smart playback interface that will allow you to control actions whenever you want. With no input from the user, QtTesting record all accomplished actions from the point you have started the record until you stop it! "Create a puppet and let it do the rest ... "<br />
<br />
Slicer developers use this library to record tutorials and test the 3D Slicer application.<br />
<br />
<br />
[[Image: QtTestingMenu.png]]<br />
<br />
{{ambox <br />
| text = ''QtTesting is an effort started by the [http://paraview.org/Wiki/Testing_design ParaView team]'' <br />
}}<br />
<br />
==Activate QtTesting==<br />
<br />
{|width="100%"<br />
|valign="top"|<br />
By default, QtTesting is not activated. You must enable it to be able to record or play a saved macro.<br />
* Open the [[Documentation/{{documentation/version}}/SlicerApplication/ApplicationSettings|Application Settings]] dialog.<br />
* On the left side, select the ''QtTesting'' panel<br />
* Enable QtTesting by toggling the checkbox<br />
* Restart Slicer<br />
|align="right"|<br />
[[Image: QtTestingSettigns.png |450px]]<br />
|}<br />
<br />
<br />
==Recorder==<br />
Recording a macro consists in observing all the high level events (or low level in some cases) that the user generate by interacting with the GUI elements. All the events are saved into a file (.xml) that can be used later to [[#Player|replay]] the recorded events in the same or different instance of the Slicer application.<br />
{|width="100%"<br />
|<br />
=== Start recording ===<br />
* From the [[Documentation/{{documentation/version}}/SlicerApplication/MainApplicationGUI#Application_Menu|menu bar]], open the ''Edit'' menu and select the ''Record Macro'' item to start recording all your following events.<br />
''A record dialog appears at the bottom left of the application''<br />
<br />
=== Record dialog ===<br />
* Shows the last event recorded<br />
* Numbers of events recorded<br />
* ''You can stop the recording anytime by clicking on the Stop button''<br />
<br />
=== Save macro ===<br />
* When the recording is stopped, a dialog shows up to ask where to save the recorded macro file.<br />
<br />
|align="right"|<br />
[[Image: QtTestingRecorderDialog.jpg |300px]]<br />
|}<br />
<br />
<br />
==Player==<br />
Recorded macros (.xml) can be replayed within Slicer sessions. Note that the success of the macro execution can depend on the original state of the application.<br />
<br />
{|width="100%"<br />
|<br />
=== How to Start ===<br />
* From the [[Documentation/{{documentation/version}}/SlicerApplication/MainApplicationGUI#Application_Menu|menu bar]], open the ''Edit'' menu and select the ''Play Macro'' item to open the player dialog.<br />
<br />
=== Player dialog ===<br />
*'''Controller widget'''<br />
** Play, pause, stop or play-step-by-step your macro.<br />
** ''Logs'' check button shows/hides information about played events and errors if any.<br />
** ''Time step'' controls the playback speed by waiting Xms before playing each event.<br />
<br />
* '''Player tab''' (''default tab'')<br />
** Show the macro file played.<br />
<br />
* '''Info tab''' :<br />
** Show the last event played.<br />
<br />
===Default settings recorded===<br />
To limit playback problems, QtTesting records automatically some of the applications settings.<br />
* General settings :<br />
** The application's geometry<br />
** The application's state<br />
** The application's name<br />
** The application's version<br />
<br />
* 3DSlicer settings :<br />
** The current layout<br />
** The current module<br />
<br />
Before each play back, the application might have different current settings, QtTesting then asks if you want to restore the settings to the record application state. To maximize the chance of a successful playback, settings must be restored to set the application into a state as much as possible similar to when the macro was recorded.<br><br />
{{ambox<br />
| type = speedy<br />
| small = left<br />
| text = It's strongly recommended to accept !<br />
}}<br />
<br />
|align="right"|<br />
[[image: QtTestintPlayererDialog.jpg | 300px]]<br />
[[image: QtTestintRestoreSettingsDialog.png | 300px]]<br />
|}<br />
<br />
<br />
==User limitations==<br />
<br />
''QtTesting in 3DSlicer is still under heavy development, some events might not be recorded properly.''<br />
<br />
===What is subject to not work :===<br />
* Some actions under submenus, mainly actions on widget.<br />
<br />
===Work, but not perfectly:===<br />
* Shifts/offsets might happen when you recording events in the 3D views.</div>BenjaminLonghttps://www.slicer.org/w/index.php?title=Documentation/Nightly/SlicerApplication/QtTesting&diff=26491Documentation/Nightly/SlicerApplication/QtTesting2012-05-30T17:40:56Z<p>BenjaminLong: /* Overview */</p>
<hr />
<div>{|width="100%"<br />
|<br />
__TOC__<br />
|align="right"|<br />
[[Image: 3DSlicerQtTesting.png]]<br />
|}<br />
=Overview=<br />
<br />
Too lazy to do the same actions over and over? QtTesting is the answer! The QtTesting library provides you with an easy way to record and play macros with 3DSlicer. Included in this library is a user-friendly recording interface that shows you what actions you're recording as well as a simple and smart playback interface that will allow you to control actions whenever you want. With no input from the user, QtTesting record all accomplished actions from the point you have started the record until you stop it! "Create a puppet and let it do the rest ... "<br />
<br />
Slicer developers use this library to record tutorials and test the 3D Slicer application.<br />
<br />
<br />
[[Image: QtTestingMenu.png]]<br />
<br />
{{ambox <br />
| text = ''QtTesting is an effort started by the [http://paraview.org/Wiki/Testing_design ParaView team]'' <br />
}}<br />
<br />
==Activate QtTesting==<br />
<br />
{|width="100%"<br />
|valign="top"|<br />
By default, QtTesting is not activated. You must enable it to be able to record or play a saved macro.<br />
* Open the [[Documentation/{{documentation/version}}/SlicerApplication/ApplicationSettings|Application Settings]] dialog.<br />
* On the left side, select the ''QtTesting'' panel<br />
* Enable QtTesting by toggling the checkbox<br />
* Restart Slicer<br />
|align="right"|<br />
[[Image: QtTestingSettigns.png |450px]]<br />
|}<br />
<br />
<br />
==Recorder==<br />
Recording a macro consists in observing all the high level events (or low level in some cases) that the user generate by interacting with the GUI elements. All the events are saved into a file (.xml) that can be used later to [[#Player|replay]] the recorded events in the same or different instance of the Slicer application.<br />
{|width="100%"<br />
|<br />
=== Start recording ===<br />
* From the [[Documentation/{{documentation/version}}/SlicerApplication/MainApplicationGUI#Application_Menu|menu bar]], open the ''Edit'' menu and select the ''Record Macro'' item to start recording all your following events.<br />
''A record dialog appears at the bottom left of the application''<br />
<br />
=== Record dialog ===<br />
* Shows the last event recorded<br />
* Numbers of events recorded<br />
* ''You can stop the recording anytime by clicking on the Stop button''<br />
<br />
=== Save macro ===<br />
* When the recording is stopped, a dialog shows up to ask where to save the recorded macro file.<br />
<br />
|align="right"|<br />
[[Image: QtTestingRecorderDialog.jpg |300px]]<br />
|}<br />
<br />
<br />
==Player==<br />
Recorded macros (.xml) can be replayed within Slicer sessions. Note that the success of the macro execution can depend on the original state of the application.<br />
<br />
{|width="100%"<br />
|<br />
=== How to Start ===<br />
* From the [[Documentation/{{documentation/version}}/SlicerApplication/MainApplicationGUI#Application_Menu|menu bar]], open the ''Edit'' menu and select the ''Play Macro'' item to open the player dialog.<br />
<br />
=== Player dialog ===<br />
*'''Controller widget'''<br />
** Play, pause, stop or play-step-by-step your macro.<br />
** ''Logs'' check button shows/hides information about played events and errors if any.<br />
** ''Time step'' controls the playback speed by waiting Xms before playing each event.<br />
<br />
* '''Player tab''' (''default tab'')<br />
** Show the macro file played.<br />
<br />
* '''Info tab''' :<br />
** Show the last event played.<br />
<br />
===Default settings recorded===<br />
To limit playback problems, QtTesting records automatically some of the applications settings.<br />
* General settings :<br />
** The application's geometry<br />
** The application's state<br />
** The application's name<br />
** The application's version<br />
<br />
* 3DSlicer settings :<br />
** The current layout<br />
** The current module<br />
<br />
Before each play back, the application might have different current settings, QtTesting then asks if you want to restore the settings to the record application state. To maximize the chance of a successful playback, settings must be restored to set the application into a state as much as possible similar to when the macro was recorded.<br><br />
{{ambox<br />
| type = speedy<br />
| small = left<br />
| text = It's strongly recommended to accept !<br />
}}<br />
<br />
|align="right"|<br />
[[image: QtTestintPlayererDialog.jpg | 300px]]<br />
[[image: QtTestintRestoreSettingsDialog.png | 300px]]<br />
|}<br />
<br />
==User limitations==<br />
<br />
''QtTesting in 3DSlicer is still under heavy development, some events might not be recorded properly.''<br />
<br />
===What is subject to not work :===<br />
* Some actions under submenus, mainly actions on widget.<br />
<br />
===Work, but not perfectly:===<br />
* Shifts/offsets might happen when you recording events in the 3D views.</div>BenjaminLonghttps://www.slicer.org/w/index.php?title=Documentation/Nightly/Developers/QtTesting&diff=26490Documentation/Nightly/Developers/QtTesting2012-05-30T17:35:09Z<p>BenjaminLong: /* Add the test in CMake */</p>
<hr />
<div>{|width="100%"<br />
|<br />
__TOC__<br />
|align="right"|<br />
[[Image: 3DSlicerQtTesting.png]]<br />
|}<br />
=Overview=<br />
<br />
QtTesting provides us a testing framework to test our application. It complements unit tests, by testing the application in its globality.<br />
<br />
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.<br><br />
<br />
<br />
=Write a 3DSlicer test using QtTesting=<br />
<br />
QtTesting framework can also be use to create module test.<br> Use the description below, but instead of <code>Slicer4/Applications/SlicerApp/Testing</code> all the path start by <code>Slicer4/Path/To/The/Modules/Testing</code><br />
<br />
Following is the different step to create a test using QtTesting framework. <br />
<br />
== Create your XML script ==<br />
See [http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/SlicerApplication/QtTesting QtTesting user Wiki] to know how to create this xml script.<br><br />
'''Save the xml script to''' <code>Slicer4/Applications/SlicerApp/Data/Input/MY_TUTORIAL_NAME_tutorial.xml''</code><br><br />
{{ambox <br />
| type = content<br />
|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]<br><br />
[[Documentation/{{documentation/version}}/Modules/SampleData Sample Data]] module according to the current Slicer version<br />
}}<br />
<br />
== Create a Python script ==<br />
''This Python test will start 3DSlicer and run the previously recorded xml script''<br />
<br />
'''''Create a python file with the following lines'''''<br />
<br />
import os<br />
import slicer<br />
import ApplicationsSlicerAppData as data<br />
filepath = data.input + '/YOUR_TEST_NAME_tutorial.xml')<br />
testUtility = slicer.app.testingUtility()<br />
success = testUtility.playTests(filepath)<br />
if not success :<br />
raise Exception('Failed to finished properly the play back !')<br />
<br />
'''''Save to the directory ''''' <code>Slicer4/Applications/SlicerApp/Testing/Python/Slicer_MY_TUTORIAL_NAME-Tutorial.py </code><br />
<br />
== Add the test in CMake ==<br />
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.<br />
<br />
Edit the file <code>Slicer4/Applications/SlicerApp/Testing/Python/CMakeLists.txt</code><br><br />
Add your test at the end of the Slicer_USE_QTTESTING condition and add the name in the <code>set_tests_properties</code> function :<br />
<br />
if(Slicer_USE_QTTESTING)<br />
{ <br />
...<br />
slicer_add_python_test(<br />
SCRIPT pythonScriptName.py<br />
SLICER_ARGS --launcher-no-splash --qt-testing)<br />
set_tests_properties(<br />
py_Slicer_NeurosurgicalPlanning-Tutorial<br />
py_Slicer_DiffusionTensorImaging-Tutorial<br />
....<br />
py_Slicer_YOUR_TUTORIAL_NAME<br />
...<br />
PROPERTIES RUN_SERIAL ON<br />
)<br />
}<br />
<br />
<br />
You just wrote a Slicer Unit Test using QtTesting framework !<br />
<br />
== Run your test==<br />
<br />
You can either use directly CTest or the pyhton script created.<br />
<br />
===Using CTest===<br />
{|width = "100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer4-Superbuild/Slicer-build<br />
$ ctest -R MY_TEST_NAME -VV<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer4-Superbuild\Slicer-build<br />
$ path\to\cmake\ctest.exe -R MY_TEST_NAME -VV<br />
|}<br />
<br />
===Using the python script===<br />
{|width="100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer4/Application/SlicerApp/Testing/Python<br />
$ python MY_TEST_NAME.py<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer4\Applicaiton\SlicerApp\Testing\Python<br />
$ path\to\Slicer4-Superbuild\python-build\PCBuild\python.exe MY_TEST_NAME.py<br />
|}<br />
<br />
=Create custom translator/player=<br />
<br />
After created a custom widget, it might be possible that all its actions are not properly recorded, or played.<br><br />
QtTesting provides us basic translator and player template, to create our custom translator and player according to the widget. <br><br />
<br />
You can use the following command to create those basic files.<br />
<br />
{|width="100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer4-Superbuild/CTK-build/QtTesting/Utilities/Scripts<br />
$ python TranslatorPlayerWizard.py MY_WIDGET_NAME<br />
$ cd ../MY_WIDGET_NAME<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer4-Superbuild<br />
$ python-build\PCBuild\python.exe CTK-build\QtTesting\Utilities\Scripts\TranslatorPlayerWizard.py MY_WIDGET_NAME<br />
$ cd ../MY_WIDGET_NAME<br />
|}<br />
<br />
{{ambox<br />
| type = <br />
| text = 4 files should have been created ! <br> <br />
<code>MY_WIDGET_NAMETranslator.cpp <br> <br />
MY_WIDGET_NAMETranslator.h <br> <br />
MY_WIDGET_NAMEPlayer.cpp <br> <br />
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.<br />
}}<br />
<br />
=Open bugs=<br />
Work in progress, following the two bug trackers :<br />
<br />
[http://na-mic.org/Mantis/search.php?project_id=3&category=QtTesting&sticky_issues=off&sortby=last_updated&dir=DESC&hide_status_id=-2 Slicer issues]<br />
<br />
[https://github.com/commontk/CTK/issues?labels=Testing&milestone=&page=1&state=open QtTesting issues]</div>BenjaminLonghttps://www.slicer.org/w/index.php?title=Documentation/Nightly/Developers/QtTesting&diff=26489Documentation/Nightly/Developers/QtTesting2012-05-30T17:34:48Z<p>BenjaminLong: /* Add the test in CMake */</p>
<hr />
<div>{|width="100%"<br />
|<br />
__TOC__<br />
|align="right"|<br />
[[Image: 3DSlicerQtTesting.png]]<br />
|}<br />
=Overview=<br />
<br />
QtTesting provides us a testing framework to test our application. It complements unit tests, by testing the application in its globality.<br />
<br />
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.<br><br />
<br />
<br />
=Write a 3DSlicer test using QtTesting=<br />
<br />
QtTesting framework can also be use to create module test.<br> Use the description below, but instead of <code>Slicer4/Applications/SlicerApp/Testing</code> all the path start by <code>Slicer4/Path/To/The/Modules/Testing</code><br />
<br />
Following is the different step to create a test using QtTesting framework. <br />
<br />
== Create your XML script ==<br />
See [http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/SlicerApplication/QtTesting QtTesting user Wiki] to know how to create this xml script.<br><br />
'''Save the xml script to''' <code>Slicer4/Applications/SlicerApp/Data/Input/MY_TUTORIAL_NAME_tutorial.xml''</code><br><br />
{{ambox <br />
| type = content<br />
|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]<br><br />
[[Documentation/{{documentation/version}}/Modules/SampleData Sample Data]] module according to the current Slicer version<br />
}}<br />
<br />
== Create a Python script ==<br />
''This Python test will start 3DSlicer and run the previously recorded xml script''<br />
<br />
'''''Create a python file with the following lines'''''<br />
<br />
import os<br />
import slicer<br />
import ApplicationsSlicerAppData as data<br />
filepath = data.input + '/YOUR_TEST_NAME_tutorial.xml')<br />
testUtility = slicer.app.testingUtility()<br />
success = testUtility.playTests(filepath)<br />
if not success :<br />
raise Exception('Failed to finished properly the play back !')<br />
<br />
'''''Save to the directory ''''' <code>Slicer4/Applications/SlicerApp/Testing/Python/Slicer_MY_TUTORIAL_NAME-Tutorial.py </code><br />
<br />
== Add the test in CMake ==<br />
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.<br />
<br />
Edit the file <code>Slicer4/Applications/SlicerApp/Testing/Python/CMakeLists.txt</code><br><br />
Add your test at the end of the Slicer_USE_QTTESTING and add the name in the <code>set_tests_properties</code> function condition:<br />
<br />
if(Slicer_USE_QTTESTING)<br />
{ <br />
...<br />
slicer_add_python_test(<br />
SCRIPT pythonScriptName.py<br />
SLICER_ARGS --launcher-no-splash --qt-testing)<br />
set_tests_properties(<br />
py_Slicer_NeurosurgicalPlanning-Tutorial<br />
py_Slicer_DiffusionTensorImaging-Tutorial<br />
....<br />
py_Slicer_YOUR_TUTORIAL_NAME<br />
...<br />
PROPERTIES RUN_SERIAL ON<br />
)<br />
}<br />
<br />
<br />
You just wrote a Slicer Unit Test using QtTesting framework !<br />
<br />
== Run your test==<br />
<br />
You can either use directly CTest or the pyhton script created.<br />
<br />
===Using CTest===<br />
{|width = "100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer4-Superbuild/Slicer-build<br />
$ ctest -R MY_TEST_NAME -VV<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer4-Superbuild\Slicer-build<br />
$ path\to\cmake\ctest.exe -R MY_TEST_NAME -VV<br />
|}<br />
<br />
===Using the python script===<br />
{|width="100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer4/Application/SlicerApp/Testing/Python<br />
$ python MY_TEST_NAME.py<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer4\Applicaiton\SlicerApp\Testing\Python<br />
$ path\to\Slicer4-Superbuild\python-build\PCBuild\python.exe MY_TEST_NAME.py<br />
|}<br />
<br />
=Create custom translator/player=<br />
<br />
After created a custom widget, it might be possible that all its actions are not properly recorded, or played.<br><br />
QtTesting provides us basic translator and player template, to create our custom translator and player according to the widget. <br><br />
<br />
You can use the following command to create those basic files.<br />
<br />
{|width="100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer4-Superbuild/CTK-build/QtTesting/Utilities/Scripts<br />
$ python TranslatorPlayerWizard.py MY_WIDGET_NAME<br />
$ cd ../MY_WIDGET_NAME<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer4-Superbuild<br />
$ python-build\PCBuild\python.exe CTK-build\QtTesting\Utilities\Scripts\TranslatorPlayerWizard.py MY_WIDGET_NAME<br />
$ cd ../MY_WIDGET_NAME<br />
|}<br />
<br />
{{ambox<br />
| type = <br />
| text = 4 files should have been created ! <br> <br />
<code>MY_WIDGET_NAMETranslator.cpp <br> <br />
MY_WIDGET_NAMETranslator.h <br> <br />
MY_WIDGET_NAMEPlayer.cpp <br> <br />
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.<br />
}}<br />
<br />
=Open bugs=<br />
Work in progress, following the two bug trackers :<br />
<br />
[http://na-mic.org/Mantis/search.php?project_id=3&category=QtTesting&sticky_issues=off&sortby=last_updated&dir=DESC&hide_status_id=-2 Slicer issues]<br />
<br />
[https://github.com/commontk/CTK/issues?labels=Testing&milestone=&page=1&state=open QtTesting issues]</div>BenjaminLonghttps://www.slicer.org/w/index.php?title=Documentation/Nightly/Developers/QtTesting&diff=26488Documentation/Nightly/Developers/QtTesting2012-05-30T17:32:52Z<p>BenjaminLong: /* Add the test in CMake */</p>
<hr />
<div>{|width="100%"<br />
|<br />
__TOC__<br />
|align="right"|<br />
[[Image: 3DSlicerQtTesting.png]]<br />
|}<br />
=Overview=<br />
<br />
QtTesting provides us a testing framework to test our application. It complements unit tests, by testing the application in its globality.<br />
<br />
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.<br><br />
<br />
<br />
=Write a 3DSlicer test using QtTesting=<br />
<br />
QtTesting framework can also be use to create module test.<br> Use the description below, but instead of <code>Slicer4/Applications/SlicerApp/Testing</code> all the path start by <code>Slicer4/Path/To/The/Modules/Testing</code><br />
<br />
Following is the different step to create a test using QtTesting framework. <br />
<br />
== Create your XML script ==<br />
See [http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/SlicerApplication/QtTesting QtTesting user Wiki] to know how to create this xml script.<br><br />
'''Save the xml script to''' <code>Slicer4/Applications/SlicerApp/Data/Input/MY_TUTORIAL_NAME_tutorial.xml''</code><br><br />
{{ambox <br />
| type = content<br />
|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]<br><br />
[[Documentation/{{documentation/version}}/Modules/SampleData Sample Data]] module according to the current Slicer version<br />
}}<br />
<br />
== Create a Python script ==<br />
''This Python test will start 3DSlicer and run the previously recorded xml script''<br />
<br />
'''''Create a python file with the following lines'''''<br />
<br />
import os<br />
import slicer<br />
import ApplicationsSlicerAppData as data<br />
filepath = data.input + '/YOUR_TEST_NAME_tutorial.xml')<br />
testUtility = slicer.app.testingUtility()<br />
success = testUtility.playTests(filepath)<br />
if not success :<br />
raise Exception('Failed to finished properly the play back !')<br />
<br />
'''''Save to the directory ''''' <code>Slicer4/Applications/SlicerApp/Testing/Python/Slicer_MY_TUTORIAL_NAME-Tutorial.py </code><br />
<br />
== Add the test in CMake ==<br />
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.<br />
<br />
Edit the file <code>Slicer4/Applications/SlicerApp/Testing/Python/CMakeLists.txt</code><br><br />
Add your test at the end of the Slicer_USE_QTTESTING condition:<br />
<br />
if(Slicer_USE_QTTESTING)<br />
{ <br />
...<br />
slicer_add_python_test(<br />
SCRIPT pythonScriptName.py<br />
SLICER_ARGS --launcher-no-splash --qt-testing)<br />
set_tests_properties(<br />
py_Slicer_NeurosurgicalPlanning-Tutorial<br />
py_Slicer_DiffusionTensorImaging-Tutorial<br />
....<br />
py_Slicer_YOUR_TUTORIAL_NAME<br />
...<br />
PROPERTIES RUN_SERIAL ON<br />
)<br />
}<br />
<br />
<br />
You just wrote a Slicer Unit Test using QtTesting framework !<br />
<br />
== Run your test==<br />
<br />
You can either use directly CTest or the pyhton script created.<br />
<br />
===Using CTest===<br />
{|width = "100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer4-Superbuild/Slicer-build<br />
$ ctest -R MY_TEST_NAME -VV<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer4-Superbuild\Slicer-build<br />
$ path\to\cmake\ctest.exe -R MY_TEST_NAME -VV<br />
|}<br />
<br />
===Using the python script===<br />
{|width="100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer4/Application/SlicerApp/Testing/Python<br />
$ python MY_TEST_NAME.py<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer4\Applicaiton\SlicerApp\Testing\Python<br />
$ path\to\Slicer4-Superbuild\python-build\PCBuild\python.exe MY_TEST_NAME.py<br />
|}<br />
<br />
=Create custom translator/player=<br />
<br />
After created a custom widget, it might be possible that all its actions are not properly recorded, or played.<br><br />
QtTesting provides us basic translator and player template, to create our custom translator and player according to the widget. <br><br />
<br />
You can use the following command to create those basic files.<br />
<br />
{|width="100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer4-Superbuild/CTK-build/QtTesting/Utilities/Scripts<br />
$ python TranslatorPlayerWizard.py MY_WIDGET_NAME<br />
$ cd ../MY_WIDGET_NAME<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer4-Superbuild<br />
$ python-build\PCBuild\python.exe CTK-build\QtTesting\Utilities\Scripts\TranslatorPlayerWizard.py MY_WIDGET_NAME<br />
$ cd ../MY_WIDGET_NAME<br />
|}<br />
<br />
{{ambox<br />
| type = <br />
| text = 4 files should have been created ! <br> <br />
<code>MY_WIDGET_NAMETranslator.cpp <br> <br />
MY_WIDGET_NAMETranslator.h <br> <br />
MY_WIDGET_NAMEPlayer.cpp <br> <br />
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.<br />
}}<br />
<br />
=Open bugs=<br />
Work in progress, following the two bug trackers :<br />
<br />
[http://na-mic.org/Mantis/search.php?project_id=3&category=QtTesting&sticky_issues=off&sortby=last_updated&dir=DESC&hide_status_id=-2 Slicer issues]<br />
<br />
[https://github.com/commontk/CTK/issues?labels=Testing&milestone=&page=1&state=open QtTesting issues]</div>BenjaminLonghttps://www.slicer.org/w/index.php?title=Documentation/Nightly/Developers/QtTesting&diff=26487Documentation/Nightly/Developers/QtTesting2012-05-30T17:30:08Z<p>BenjaminLong: /* Add the test in CMake */</p>
<hr />
<div>{|width="100%"<br />
|<br />
__TOC__<br />
|align="right"|<br />
[[Image: 3DSlicerQtTesting.png]]<br />
|}<br />
=Overview=<br />
<br />
QtTesting provides us a testing framework to test our application. It complements unit tests, by testing the application in its globality.<br />
<br />
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.<br><br />
<br />
<br />
=Write a 3DSlicer test using QtTesting=<br />
<br />
QtTesting framework can also be use to create module test.<br> Use the description below, but instead of <code>Slicer4/Applications/SlicerApp/Testing</code> all the path start by <code>Slicer4/Path/To/The/Modules/Testing</code><br />
<br />
Following is the different step to create a test using QtTesting framework. <br />
<br />
== Create your XML script ==<br />
See [http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/SlicerApplication/QtTesting QtTesting user Wiki] to know how to create this xml script.<br><br />
'''Save the xml script to''' <code>Slicer4/Applications/SlicerApp/Data/Input/MY_TUTORIAL_NAME_tutorial.xml''</code><br><br />
{{ambox <br />
| type = content<br />
|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]<br><br />
[[Documentation/{{documentation/version}}/Modules/SampleData Sample Data]] module according to the current Slicer version<br />
}}<br />
<br />
== Create a Python script ==<br />
''This Python test will start 3DSlicer and run the previously recorded xml script''<br />
<br />
'''''Create a python file with the following lines'''''<br />
<br />
import os<br />
import slicer<br />
import ApplicationsSlicerAppData as data<br />
filepath = data.input + '/YOUR_TEST_NAME_tutorial.xml')<br />
testUtility = slicer.app.testingUtility()<br />
success = testUtility.playTests(filepath)<br />
if not success :<br />
raise Exception('Failed to finished properly the play back !')<br />
<br />
'''''Save to the directory ''''' <code>Slicer4/Applications/SlicerApp/Testing/Python/Slicer_MY_TUTORIAL_NAME-Tutorial.py </code><br />
<br />
== Add the test in CMake ==<br />
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.<br />
<br />
Edit the file <code>Slicer4/Applications/SlicerApp/Testing/Python/CMakeLists.txt</code><br><br />
Add your test at the end of the Slicer_USE_QTTESTING condition:<br />
<br />
if(Slicer_USE_QTTESTING)<br />
{ <br />
...<br />
slicer_add_python_test(<br />
SCRIPT pythonScriptName.py<br />
SLICER_ARGS --launcher-no-splash --qt-testing)<br />
<br />
}<br />
<br />
<br />
You just wrote a Slicer Unit Test using QtTesting framework !<br />
<br />
== Run your test==<br />
<br />
You can either use directly CTest or the pyhton script created.<br />
<br />
===Using CTest===<br />
{|width = "100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer4-Superbuild/Slicer-build<br />
$ ctest -R MY_TEST_NAME -VV<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer4-Superbuild\Slicer-build<br />
$ path\to\cmake\ctest.exe -R MY_TEST_NAME -VV<br />
|}<br />
<br />
===Using the python script===<br />
{|width="100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer4/Application/SlicerApp/Testing/Python<br />
$ python MY_TEST_NAME.py<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer4\Applicaiton\SlicerApp\Testing\Python<br />
$ path\to\Slicer4-Superbuild\python-build\PCBuild\python.exe MY_TEST_NAME.py<br />
|}<br />
<br />
=Create custom translator/player=<br />
<br />
After created a custom widget, it might be possible that all its actions are not properly recorded, or played.<br><br />
QtTesting provides us basic translator and player template, to create our custom translator and player according to the widget. <br><br />
<br />
You can use the following command to create those basic files.<br />
<br />
{|width="100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer4-Superbuild/CTK-build/QtTesting/Utilities/Scripts<br />
$ python TranslatorPlayerWizard.py MY_WIDGET_NAME<br />
$ cd ../MY_WIDGET_NAME<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer4-Superbuild<br />
$ python-build\PCBuild\python.exe CTK-build\QtTesting\Utilities\Scripts\TranslatorPlayerWizard.py MY_WIDGET_NAME<br />
$ cd ../MY_WIDGET_NAME<br />
|}<br />
<br />
{{ambox<br />
| type = <br />
| text = 4 files should have been created ! <br> <br />
<code>MY_WIDGET_NAMETranslator.cpp <br> <br />
MY_WIDGET_NAMETranslator.h <br> <br />
MY_WIDGET_NAMEPlayer.cpp <br> <br />
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.<br />
}}<br />
<br />
=Open bugs=<br />
Work in progress, following the two bug trackers :<br />
<br />
[http://na-mic.org/Mantis/search.php?project_id=3&category=QtTesting&sticky_issues=off&sortby=last_updated&dir=DESC&hide_status_id=-2 Slicer issues]<br />
<br />
[https://github.com/commontk/CTK/issues?labels=Testing&milestone=&page=1&state=open QtTesting issues]</div>BenjaminLonghttps://www.slicer.org/w/index.php?title=Documentation/Nightly/Developers/QtTesting&diff=26486Documentation/Nightly/Developers/QtTesting2012-05-30T17:29:48Z<p>BenjaminLong: /* Create a Python script */</p>
<hr />
<div>{|width="100%"<br />
|<br />
__TOC__<br />
|align="right"|<br />
[[Image: 3DSlicerQtTesting.png]]<br />
|}<br />
=Overview=<br />
<br />
QtTesting provides us a testing framework to test our application. It complements unit tests, by testing the application in its globality.<br />
<br />
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.<br><br />
<br />
<br />
=Write a 3DSlicer test using QtTesting=<br />
<br />
QtTesting framework can also be use to create module test.<br> Use the description below, but instead of <code>Slicer4/Applications/SlicerApp/Testing</code> all the path start by <code>Slicer4/Path/To/The/Modules/Testing</code><br />
<br />
Following is the different step to create a test using QtTesting framework. <br />
<br />
== Create your XML script ==<br />
See [http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/SlicerApplication/QtTesting QtTesting user Wiki] to know how to create this xml script.<br><br />
'''Save the xml script to''' <code>Slicer4/Applications/SlicerApp/Data/Input/MY_TUTORIAL_NAME_tutorial.xml''</code><br><br />
{{ambox <br />
| type = content<br />
|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]<br><br />
[[Documentation/{{documentation/version}}/Modules/SampleData Sample Data]] module according to the current Slicer version<br />
}}<br />
<br />
== Create a Python script ==<br />
''This Python test will start 3DSlicer and run the previously recorded xml script''<br />
<br />
'''''Create a python file with the following lines'''''<br />
<br />
import os<br />
import slicer<br />
import ApplicationsSlicerAppData as data<br />
filepath = data.input + '/YOUR_TEST_NAME_tutorial.xml')<br />
testUtility = slicer.app.testingUtility()<br />
success = testUtility.playTests(filepath)<br />
if not success :<br />
raise Exception('Failed to finished properly the play back !')<br />
<br />
'''''Save to the directory ''''' <code>Slicer4/Applications/SlicerApp/Testing/Python/Slicer_MY_TUTORIAL_NAME-Tutorial.py </code><br />
<br />
== Add the test in CMake ==<br />
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.<br />
<br />
Edit the file <code>Slicer4/Applications/SlicerApp/Testing/Python/CMakeLists.txt</code><br><br />
Add your test at the end of the Slicer_USE_QTTESTING condition:<br />
<br />
if(Slicer_USE_QTTESTING)<br />
{ <br />
...<br />
slicer_add_python_test(<br />
SCRIPT pythonScriptName.py<br />
SLICER_ARGS --launcher-no-splash --qt-testing)<br />
}<br />
<br />
<br />
You just wrote a Slicer Unit Test using QtTesting framework !<br />
<br />
<br />
== Run your test==<br />
<br />
You can either use directly CTest or the pyhton script created.<br />
<br />
===Using CTest===<br />
{|width = "100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer4-Superbuild/Slicer-build<br />
$ ctest -R MY_TEST_NAME -VV<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer4-Superbuild\Slicer-build<br />
$ path\to\cmake\ctest.exe -R MY_TEST_NAME -VV<br />
|}<br />
<br />
===Using the python script===<br />
{|width="100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer4/Application/SlicerApp/Testing/Python<br />
$ python MY_TEST_NAME.py<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer4\Applicaiton\SlicerApp\Testing\Python<br />
$ path\to\Slicer4-Superbuild\python-build\PCBuild\python.exe MY_TEST_NAME.py<br />
|}<br />
<br />
=Create custom translator/player=<br />
<br />
After created a custom widget, it might be possible that all its actions are not properly recorded, or played.<br><br />
QtTesting provides us basic translator and player template, to create our custom translator and player according to the widget. <br><br />
<br />
You can use the following command to create those basic files.<br />
<br />
{|width="100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer4-Superbuild/CTK-build/QtTesting/Utilities/Scripts<br />
$ python TranslatorPlayerWizard.py MY_WIDGET_NAME<br />
$ cd ../MY_WIDGET_NAME<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer4-Superbuild<br />
$ python-build\PCBuild\python.exe CTK-build\QtTesting\Utilities\Scripts\TranslatorPlayerWizard.py MY_WIDGET_NAME<br />
$ cd ../MY_WIDGET_NAME<br />
|}<br />
<br />
{{ambox<br />
| type = <br />
| text = 4 files should have been created ! <br> <br />
<code>MY_WIDGET_NAMETranslator.cpp <br> <br />
MY_WIDGET_NAMETranslator.h <br> <br />
MY_WIDGET_NAMEPlayer.cpp <br> <br />
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.<br />
}}<br />
<br />
=Open bugs=<br />
Work in progress, following the two bug trackers :<br />
<br />
[http://na-mic.org/Mantis/search.php?project_id=3&category=QtTesting&sticky_issues=off&sortby=last_updated&dir=DESC&hide_status_id=-2 Slicer issues]<br />
<br />
[https://github.com/commontk/CTK/issues?labels=Testing&milestone=&page=1&state=open QtTesting issues]</div>BenjaminLonghttps://www.slicer.org/w/index.php?title=Documentation/Nightly/Developers/QtTesting&diff=26485Documentation/Nightly/Developers/QtTesting2012-05-30T17:29:16Z<p>BenjaminLong: /* Create your XML script */</p>
<hr />
<div>{|width="100%"<br />
|<br />
__TOC__<br />
|align="right"|<br />
[[Image: 3DSlicerQtTesting.png]]<br />
|}<br />
=Overview=<br />
<br />
QtTesting provides us a testing framework to test our application. It complements unit tests, by testing the application in its globality.<br />
<br />
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.<br><br />
<br />
<br />
=Write a 3DSlicer test using QtTesting=<br />
<br />
QtTesting framework can also be use to create module test.<br> Use the description below, but instead of <code>Slicer4/Applications/SlicerApp/Testing</code> all the path start by <code>Slicer4/Path/To/The/Modules/Testing</code><br />
<br />
Following is the different step to create a test using QtTesting framework. <br />
<br />
== Create your XML script ==<br />
See [http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/SlicerApplication/QtTesting QtTesting user Wiki] to know how to create this xml script.<br><br />
'''Save the xml script to''' <code>Slicer4/Applications/SlicerApp/Data/Input/MY_TUTORIAL_NAME_tutorial.xml''</code><br><br />
{{ambox <br />
| type = content<br />
|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]<br><br />
[[Documentation/{{documentation/version}}/Modules/SampleData Sample Data]] module according to the current Slicer version<br />
}}<br />
<br />
== Create a Python script ==<br />
''This Python test will start 3DSlicer and run the previously recorded xml script''<br />
<br />
'''''Create a python file with the following lines'''''<br />
<br />
import os<br />
import slicer<br />
import ApplicationsSlicerAppData as data<br />
filepath = data.input + '/YOUR_TEST_NAME_tutorial.xml')<br />
testUtility = slicer.app.testingUtility()<br />
success = testUtility.playTests(filepath)<br />
if not success :<br />
raise Exception('Failed to finished properly the play back !')<br />
<br />
'''''Save to the directory ''''' <code>Slicer4/Applications/SlicerApp/Testing/Python/Slicer4.X.X_tutorial_MY_TUTORIAL_NAME.py </code><br />
<br />
== Add the test in CMake ==<br />
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.<br />
<br />
Edit the file <code>Slicer4/Applications/SlicerApp/Testing/Python/CMakeLists.txt</code><br><br />
Add your test at the end of the Slicer_USE_QTTESTING condition:<br />
<br />
if(Slicer_USE_QTTESTING)<br />
{ <br />
...<br />
slicer_add_python_test(<br />
SCRIPT pythonScriptName.py<br />
SLICER_ARGS --launcher-no-splash --qt-testing)<br />
}<br />
<br />
<br />
You just wrote a Slicer Unit Test using QtTesting framework !<br />
<br />
<br />
== Run your test==<br />
<br />
You can either use directly CTest or the pyhton script created.<br />
<br />
===Using CTest===<br />
{|width = "100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer4-Superbuild/Slicer-build<br />
$ ctest -R MY_TEST_NAME -VV<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer4-Superbuild\Slicer-build<br />
$ path\to\cmake\ctest.exe -R MY_TEST_NAME -VV<br />
|}<br />
<br />
===Using the python script===<br />
{|width="100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer4/Application/SlicerApp/Testing/Python<br />
$ python MY_TEST_NAME.py<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer4\Applicaiton\SlicerApp\Testing\Python<br />
$ path\to\Slicer4-Superbuild\python-build\PCBuild\python.exe MY_TEST_NAME.py<br />
|}<br />
<br />
=Create custom translator/player=<br />
<br />
After created a custom widget, it might be possible that all its actions are not properly recorded, or played.<br><br />
QtTesting provides us basic translator and player template, to create our custom translator and player according to the widget. <br><br />
<br />
You can use the following command to create those basic files.<br />
<br />
{|width="100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer4-Superbuild/CTK-build/QtTesting/Utilities/Scripts<br />
$ python TranslatorPlayerWizard.py MY_WIDGET_NAME<br />
$ cd ../MY_WIDGET_NAME<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer4-Superbuild<br />
$ python-build\PCBuild\python.exe CTK-build\QtTesting\Utilities\Scripts\TranslatorPlayerWizard.py MY_WIDGET_NAME<br />
$ cd ../MY_WIDGET_NAME<br />
|}<br />
<br />
{{ambox<br />
| type = <br />
| text = 4 files should have been created ! <br> <br />
<code>MY_WIDGET_NAMETranslator.cpp <br> <br />
MY_WIDGET_NAMETranslator.h <br> <br />
MY_WIDGET_NAMEPlayer.cpp <br> <br />
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.<br />
}}<br />
<br />
=Open bugs=<br />
Work in progress, following the two bug trackers :<br />
<br />
[http://na-mic.org/Mantis/search.php?project_id=3&category=QtTesting&sticky_issues=off&sortby=last_updated&dir=DESC&hide_status_id=-2 Slicer issues]<br />
<br />
[https://github.com/commontk/CTK/issues?labels=Testing&milestone=&page=1&state=open QtTesting issues]</div>BenjaminLonghttps://www.slicer.org/w/index.php?title=Documentation/Nightly/Developers/QtTesting&diff=26484Documentation/Nightly/Developers/QtTesting2012-05-30T17:27:43Z<p>BenjaminLong: /* Create a Python script */</p>
<hr />
<div>{|width="100%"<br />
|<br />
__TOC__<br />
|align="right"|<br />
[[Image: 3DSlicerQtTesting.png]]<br />
|}<br />
=Overview=<br />
<br />
QtTesting provides us a testing framework to test our application. It complements unit tests, by testing the application in its globality.<br />
<br />
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.<br><br />
<br />
<br />
=Write a 3DSlicer test using QtTesting=<br />
<br />
QtTesting framework can also be use to create module test.<br> Use the description below, but instead of <code>Slicer4/Applications/SlicerApp/Testing</code> all the path start by <code>Slicer4/Path/To/The/Modules/Testing</code><br />
<br />
Following is the different step to create a test using QtTesting framework. <br />
<br />
== Create your XML script ==<br />
See [http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/SlicerApplication/QtTesting QtTesting user Wiki] to know how to create this xml script.<br><br />
'''Save the xml script to''' <code>Slicer4/Applications/SlicerApp/Testing/QtTesting/Slicer4.X.X_tutorial_MY_TUTORIAL_NAME.xml''</code><br><br />
{{ambox <br />
| type = content<br />
|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]<br><br />
[[Documentation/{{documentation/version}}/Modules/SampleData Sample Data]] module according to the current Slicer version<br />
}}<br />
<br />
<br />
== Create a Python script ==<br />
''This Python test will start 3DSlicer and run the previously recorded xml script''<br />
<br />
'''''Create a python file with the following lines'''''<br />
<br />
import os<br />
import slicer<br />
import ApplicationsSlicerAppData as data<br />
filepath = data.input + '/YOUR_TEST_NAME_tutorial.xml')<br />
testUtility = slicer.app.testingUtility()<br />
success = testUtility.playTests(filepath)<br />
if not success :<br />
raise Exception('Failed to finished properly the play back !')<br />
<br />
'''''Save to the directory ''''' <code>Slicer4/Applications/SlicerApp/Testing/Python/Slicer4.X.X_tutorial_MY_TUTORIAL_NAME.py </code><br />
<br />
== Add the test in CMake ==<br />
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.<br />
<br />
Edit the file <code>Slicer4/Applications/SlicerApp/Testing/Python/CMakeLists.txt</code><br><br />
Add your test at the end of the Slicer_USE_QTTESTING condition:<br />
<br />
if(Slicer_USE_QTTESTING)<br />
{ <br />
...<br />
slicer_add_python_test(<br />
SCRIPT pythonScriptName.py<br />
SLICER_ARGS --launcher-no-splash --qt-testing)<br />
}<br />
<br />
<br />
You just wrote a Slicer Unit Test using QtTesting framework !<br />
<br />
<br />
== Run your test==<br />
<br />
You can either use directly CTest or the pyhton script created.<br />
<br />
===Using CTest===<br />
{|width = "100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer4-Superbuild/Slicer-build<br />
$ ctest -R MY_TEST_NAME -VV<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer4-Superbuild\Slicer-build<br />
$ path\to\cmake\ctest.exe -R MY_TEST_NAME -VV<br />
|}<br />
<br />
===Using the python script===<br />
{|width="100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer4/Application/SlicerApp/Testing/Python<br />
$ python MY_TEST_NAME.py<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer4\Applicaiton\SlicerApp\Testing\Python<br />
$ path\to\Slicer4-Superbuild\python-build\PCBuild\python.exe MY_TEST_NAME.py<br />
|}<br />
<br />
=Create custom translator/player=<br />
<br />
After created a custom widget, it might be possible that all its actions are not properly recorded, or played.<br><br />
QtTesting provides us basic translator and player template, to create our custom translator and player according to the widget. <br><br />
<br />
You can use the following command to create those basic files.<br />
<br />
{|width="100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer4-Superbuild/CTK-build/QtTesting/Utilities/Scripts<br />
$ python TranslatorPlayerWizard.py MY_WIDGET_NAME<br />
$ cd ../MY_WIDGET_NAME<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer4-Superbuild<br />
$ python-build\PCBuild\python.exe CTK-build\QtTesting\Utilities\Scripts\TranslatorPlayerWizard.py MY_WIDGET_NAME<br />
$ cd ../MY_WIDGET_NAME<br />
|}<br />
<br />
{{ambox<br />
| type = <br />
| text = 4 files should have been created ! <br> <br />
<code>MY_WIDGET_NAMETranslator.cpp <br> <br />
MY_WIDGET_NAMETranslator.h <br> <br />
MY_WIDGET_NAMEPlayer.cpp <br> <br />
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.<br />
}}<br />
<br />
=Open bugs=<br />
Work in progress, following the two bug trackers :<br />
<br />
[http://na-mic.org/Mantis/search.php?project_id=3&category=QtTesting&sticky_issues=off&sortby=last_updated&dir=DESC&hide_status_id=-2 Slicer issues]<br />
<br />
[https://github.com/commontk/CTK/issues?labels=Testing&milestone=&page=1&state=open QtTesting issues]</div>BenjaminLonghttps://www.slicer.org/w/index.php?title=Documentation/Nightly/Developers/QtTesting&diff=26483Documentation/Nightly/Developers/QtTesting2012-05-30T17:25:38Z<p>BenjaminLong: /* Create custom translator/player */</p>
<hr />
<div>{|width="100%"<br />
|<br />
__TOC__<br />
|align="right"|<br />
[[Image: 3DSlicerQtTesting.png]]<br />
|}<br />
=Overview=<br />
<br />
QtTesting provides us a testing framework to test our application. It complements unit tests, by testing the application in its globality.<br />
<br />
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.<br><br />
<br />
<br />
=Write a 3DSlicer test using QtTesting=<br />
<br />
QtTesting framework can also be use to create module test.<br> Use the description below, but instead of <code>Slicer4/Applications/SlicerApp/Testing</code> all the path start by <code>Slicer4/Path/To/The/Modules/Testing</code><br />
<br />
Following is the different step to create a test using QtTesting framework. <br />
<br />
== Create your XML script ==<br />
See [http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/SlicerApplication/QtTesting QtTesting user Wiki] to know how to create this xml script.<br><br />
'''Save the xml script to''' <code>Slicer4/Applications/SlicerApp/Testing/QtTesting/Slicer4.X.X_tutorial_MY_TUTORIAL_NAME.xml''</code><br><br />
{{ambox <br />
| type = content<br />
|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]<br><br />
[[Documentation/{{documentation/version}}/Modules/SampleData Sample Data]] module according to the current Slicer version<br />
}}<br />
<br />
<br />
== Create a Python script ==<br />
''This Python test will start 3DSlicer and run the previously recorded xml script''<br />
<br />
'''''Create a python file with the following lines'''''<br />
<br />
import slicer<br />
import slicer.testing<br />
import slicer.util<br />
filepath = os.environ['SLICER_HOME'] + 'path/to/xml/script.xml'<br />
testUtility = slicer.app.testingUtility()<br />
success = testUtility.playTests(filepath)<br />
if success :<br />
slicer.util.exit(EXIT_SUCCESS)<br />
else:<br />
slicer.util.exit(EXIT_FAILURE)<br />
<br />
'''''Save to the directory ''''' <code>Slicer4/Applications/SlicerApp/Testing/Python/Slicer4.X.X_tutorial_MY_TUTORIAL_NAME.py </code><br />
<br />
<br />
== Add the test in CMake ==<br />
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.<br />
<br />
Edit the file <code>Slicer4/Applications/SlicerApp/Testing/Python/CMakeLists.txt</code><br><br />
Add your test at the end of the Slicer_USE_QTTESTING condition:<br />
<br />
if(Slicer_USE_QTTESTING)<br />
{ <br />
...<br />
slicer_add_python_test(<br />
SCRIPT pythonScriptName.py<br />
SLICER_ARGS --launcher-no-splash --qt-testing)<br />
}<br />
<br />
<br />
You just wrote a Slicer Unit Test using QtTesting framework !<br />
<br />
<br />
== Run your test==<br />
<br />
You can either use directly CTest or the pyhton script created.<br />
<br />
===Using CTest===<br />
{|width = "100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer4-Superbuild/Slicer-build<br />
$ ctest -R MY_TEST_NAME -VV<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer4-Superbuild\Slicer-build<br />
$ path\to\cmake\ctest.exe -R MY_TEST_NAME -VV<br />
|}<br />
<br />
===Using the python script===<br />
{|width="100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer4/Application/SlicerApp/Testing/Python<br />
$ python MY_TEST_NAME.py<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer4\Applicaiton\SlicerApp\Testing\Python<br />
$ path\to\Slicer4-Superbuild\python-build\PCBuild\python.exe MY_TEST_NAME.py<br />
|}<br />
<br />
=Create custom translator/player=<br />
<br />
After created a custom widget, it might be possible that all its actions are not properly recorded, or played.<br><br />
QtTesting provides us basic translator and player template, to create our custom translator and player according to the widget. <br><br />
<br />
You can use the following command to create those basic files.<br />
<br />
{|width="100%"<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Linux<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Mac<br />
! style="border-bottom: 1px solid darkgrey;font-size: 75%;"|Windows<br />
|-<br />
| colspan=2; valign="top" |<br />
You need to open a terminal.<br>Then type in the terminal:<br><br><br />
$ cd path/to/Slicer4-Superbuild/CTK-build/QtTesting/Utilities/Scripts<br />
$ python TranslatorPlayerWizard.py MY_WIDGET_NAME<br />
$ cd ../MY_WIDGET_NAME<br />
| valign="top" |<br />
You need to open a terminal.<br><br />
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt<br><br />
Then type in the terminal:<br><br />
$ cd path\to\Slicer4-Superbuild<br />
$ python-build\PCBuild\python.exe CTK-build\QtTesting\Utilities\Scripts\TranslatorPlayerWizard.py MY_WIDGET_NAME<br />
$ cd ../MY_WIDGET_NAME<br />
|}<br />
<br />
{{ambox<br />
| type = <br />
| text = 4 files should have been created ! <br> <br />
<code>MY_WIDGET_NAMETranslator.cpp <br> <br />
MY_WIDGET_NAMETranslator.h <br> <br />
MY_WIDGET_NAMEPlayer.cpp <br> <br />
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.<br />
}}<br />
<br />
=Open bugs=<br />
Work in progress, following the two bug trackers :<br />
<br />
[http://na-mic.org/Mantis/search.php?project_id=3&category=QtTesting&sticky_issues=off&sortby=last_updated&dir=DESC&hide_status_id=-2 Slicer issues]<br />
<br />
[https://github.com/commontk/CTK/issues?labels=Testing&milestone=&page=1&state=open QtTesting issues]</div>BenjaminLonghttps://www.slicer.org/w/index.php?title=File:QtTestintRestoreSettingsDialog.png&diff=26482File:QtTestintRestoreSettingsDialog.png2012-05-30T17:24:08Z<p>BenjaminLong: </p>
<hr />
<div></div>BenjaminLong