Documentation/Widget testing

From Commontk
Jump to navigationJump to search
Home < Documentation < Widget testing

Overview

Testing of both CTK widgets and application built on top of CTK could leverage the capabilities offered by the QtTesting library developed by Paraview folks.


How added the testing framework to CTK :

  • Turn the variable CTK_USE_QTTESTING into ON.


If the option CTK_USE_QTTESTING is enabled, the build system will :

  1. Download external project QtTesting
  2. Compile the CTKQtTesting Library
    • Including the class :
      • ctkEventTranslaterPlayerWidget : Widget used by the Unit Test - Image
      • ctkQtTestingUtility : Class used by the application - inherits from pqTestUtility
      • ctkXMLEventObserver : Recover the Event and write the .xml file.
      • ctkXMLEventSource : Read the .xml file and create the events.
  3. For CTKWidget - CTKVisualizationWidget - CTKCoreWidget :
    • Include the event translator and player required for custom widgets. (Located in the same folder as their associated widget sources)
  4. If BUILD_TESTING is enabled: widgets EventTranslatorTests will be compiled.
    • These tests will use ctkEventTranslaterPlayerWidget and ensure that events associated with widgets can be properly recorded and played.


Note Note:
Option CTK_USE_QTTESTING will be automatically enabled if BUILD_TESTING is ON

Adding the testing framework into your application

Adding the testing framework will allow users to recover script, but also a easy way to create tutorial or to test all the widget.
You can see the application exemple created in CTK to have an exemple:

How

Follow these steps to add this testing framework to your application.

  1. Create a variable ctkQtTestingUtiliy - can be added to your mainWindow class.
    • And initialize this variable as following :
this->TestUtility = new ctkQtTestingUtility(this);
this->TestUtility->addEventObserver("xml", new ctkXMLEventObserver(this));
this->TestUtility->addEventSource("xml", new ctkXMLEventSource(this));

Note Note: You can have your own EventObserver and EventSource

  1. Create a button Record, and link it to the ctkQtTestUtility slot record
  2. Create a button Play, and link it to the ctkQtTestingUtility slot play
QObject::connect(Ui.RecordButton, SIGNAL(clicked(bool)), this, SLOT(record()));
QObject::connect(Ui.PlayBackButton, SIGNAL(clicked(bool)), this, SLOT(play()));

Limits

Note that there are still severals limits to this testing framework :

  1. The ctkVTKRenderView had to have the same size between the record and the playback.
    • To solve the issue, ctkTestingUtility record all the application property - size, state, font ... - and before a playback, if these property are differents, ask the user if he wants to load the settings.
      Note Note: We are working on this limit to find a better solution.
  2. All the CTK Widgets are not yet tested - Below the summary table -

Issues found on QtTesting

  • QSpinBox/QDoubleSpinBox :
    • A long click on the up/down arrow -> just one click even if the value change severals times.
    • Fast click -> Double click -> no effect.
    • clik on the up/down arrow just after editing the spin Box -> no effect.

Solve : Contribut to the QtTesting by modified the pqSpinBoxEventTranslator Znak A-14.png
Here the link to my Github for the QSpinBox
Here the link to my Github for the QDoublSpinBox


  • In pq3DView :
    • The scroll button has no effect - Implemented for ctk.
    • Shift between the current/Expected image.

Solve : new Implementation with the ctkVTKRenderViewEventTranslator and the ctkVTKRenderViewEventPlayer : Yes check.png

  1. Change the normalization into a normalization by the widget center.
  2. Implemented the scroll action
  3. Add a better rounded when we cast from double to int to not have shift issue.


  • QComboBox when it is editable :
    • The hight-event "set_sting" crash if we edit the comboBox.
      • Exemple : If we have an item "foo", we are going to edit the comboBox with "f", but the item "f" doesn't exist, and the player will crash.

Solve : ... X mark.png

Building

Milestones

  1. Integrate QtTesting has an external projects Yes check.png
  2. Add unit test to all the widget - Below, the summuray table -
    1. Implement ctkEventTranslaterPlayerWidget Yes check.png
    2. Create custom translator/player if needed Znak A-14.png
    3. Implement widgets EventTranslatorTests Znak A-14.png
  3. Create an Application test - ctkQtTesting - Yes check.png

Player/Translators Widget Testing

Summury table, to know each widgets' state.
The state can be Done : Yes check.png , Done with QtTesting issue : Yes check.pngZnak A-14.png , in progress : Znak A-14.png , or without unit test: X mark.png.

CTKWidgets
Widgets State Priority Notes
ctkActionsWidget Yes check.png
ctkAddRemoveComboBox Yes check.png
ctkAxesWidget Yes check.png Translator/player implemented
ctkBasePopupWidget NA ctkPopupWidget inherit of it. See ctkPopupWidget
ctkButtonGroup Yes check.png
ctkCheckableComboBox Yes check.png
ctkCheckableHeaderView Yes check.png
ctkCheckBoxPixmaps X mark.png Not used in Slicer
ctkCheckablePushButton Yes check.png Not used in Slicer
ctkComboBox Yes check.png
ctkCompleter NA
ctkCollapsibleButton Yes check.png
ctkCollapsibleGroupBox Yes check.png
ctkColorDialog Yes check.png
ctkColorPickerButton Yes check.png
ctkConsole Yes check.png May have a problem with the command
ctkConfirmExitDialog X mark.png
ctkCoordinatesWidget Yes check.png
ctkCrosshairLabel X mark.png
ctkDateRangeWidget X mark.png Problem with QDateTimer
ctkDirectoryButton Yes check.png - TO VERIFY Value OK but no dialog
ctkDoubleRangeSlider Yes check.png
ctkDoubleSlider Yes check.png
ctkDynamicSpacer NA
ctkErrorLogStatusMessageHandler NA Not a Widget
ctkErrorLogWidget X mark.png
ctkExpandButton Yes check.png
ctkFileDialog Yes check.png
ctkFittedTextBrowser NA This widget just display text.
ctkFlowLayout NA Layout are not tested through the event translator/player mechanism
ctkFontButton Yes check.png
ctkIconEnginePlugin NA Plugin are not tested through the event translator/player mechanism
ctkLayoutManager NA
ctkMaterialPropertyPreviewLabel NA
ctkMaterialPropertyWidget Yes check.png
ctkMatrixWidget Yes check.png no visuel effects
ctkMenuButton X mark.png Use in Slicer ?
ctkMenuComboBox Yes check.png Developer should make sure menus have a parent. See https://bugreports.qt.nokia.com/browse/QTBUG-20929
ctkModalityWidget Yes check.png
ctkPathLineEdit Yes check.png Note that the first time the listview is displayed, it will show on the top left corner of the screen.
ctkPixmapIconEngine NA
ctkPopupWidget Yes check.png
ctkQImageView NA
ctkRangeSlider Yes check.png
ctkRangeWidget Yes check.png
ctkScreenshotDialog X mark.png
ctkSearchBox Yes check.png
ctkSettings NA
ctkSettingsDialog Yes check.png
ctkSettingsPanel Yes check.png See ctkSettingsDialog
ctkSignalMapper NA This object is not a widget and doesn't have to be tested through the event translator/player mechanism
ctkSimpleLayoutManager NA
ctkSliderWidget Znak A-14.png Translator and player if popup
ctkTestApplication NA This is a utility class. Shouldn't be tested using the event translator/player mechanism
ctkThumbnailListWidget X mark.png
ctkThumbnailWidget X mark.png
ctkToolTipTrapper NA This is a utility class. Shouldn't be tested using the event translator/player mechanism
ctkTransferFunctionBarsItem X mark.png
ctkTransferFunctionControlPointsItem X mark.png
ctkTransferFunctionGradientItem X mark.png
ctkTransferFunctionItem X mark.png
ctkTransferFunctionScene X mark.png
ctkTransferFunctionView X mark.png
ctkTreeComboBox Yes check.png Note: This won't work if there multiple items with a similar name. This is not an issue in Slicer since selection is based on string
ctkWidgetsUtils NA This is a utility class. Shouldn't be tested using the event translator/player mechanism
ctkWorkflowAbstractPagedWidget X mark.png
ctkWorkflowButtonBoxWidget X mark.png
ctkWorkflowGroupBox X mark.png
ctkWorkflowStackedWidget X mark.png
ctkWorkflowTabWidget X mark.png
ctkWorkflowWidget X mark.png
ctkWorkflowWidgetStep X mark.png
CTKVisualizationVTKWidgets
Widgets State Priority Notes
ctkVTKAbstractMatrixWidget Yes check.png See ctkVTKMatrixWidget
ctkVTKAbstractView Yes check.png See ctkVTKRenderView
ctkVTKChartView X mark.png
ctkVTKDataSetArrayComboBox Yes check.png
ctkVTKDataSetModel Yes check.png
ctkVTKMagnifyView X mark.png Not used in Slicer
ctkVTKMatrixWidget Yes check.png See ctkVTKMatrixWidget - There is no need for specific translator & player
ctkVTKRenderView Yes check.png Translator/Player implemented
What we want :
- Wheel event Yes check.png
- Better normalization Yes check.png
- Not working if the renderView has a different size
ctkVTKScalarBarWidget Yes check.pngZnak A-14.png QSpinBox issue + key "."(pad) on the line edit
ctkVTKScalarsToColorsUtils X mark.png
ctkVTKScalarsToColorsView X mark.png
ctkVTKScalarsToColorsWidget X mark.png
ctkVTKSliceView Yes check.png Since it's based on QVTKWidget - See ctkVTKRenderView translator & player
ctkVTKSurfaceMaterialPropertyWidget Znak A-14.png
ctkVTKTextPropertyWidget Yes check.png
ctkVTKThresholdWidget X mark.png
ctkVTKThumbnailView X mark.png
ctkVTKVolumePropertyWidget Znak A-14.png
ctkVTKWidgetsUtils NA
CTKDICOMWidgets
Widgets State Priority Notes
ctkDICOMAppWidget X mark.png
ctkDICOMDatasetView X mark.png
ctkDICOMDirectoryListWidget X mark.png
ctkDICOMImage X mark.png
ctkDICOMImportWidget X mark.png
ctkDICOMItemTreeModel X mark.png
ctkDICOMListenerWidget X mark.png
ctkDICOMQueryResultsTabWidget X mark.png
ctkDICOMQueryRetrieveWidget X mark.png
ctkDICOMQueryWidget X mark.png
ctkDICOMServerNodeWidget X mark.png
ctkDICOMThumbnailGenerator X mark.png
ctkDICOMThumbnailListWidget X mark.png
qMRMLWidgets
Widgets State Priority Notes
qMRMLCaptureToolBar Znak A-14.png
qMRMLCheckableNodeComboBox Yes check.png
qMRMLClipNodeWidget Yes check.png
qMRMLCollapsibleButton Yes check.png
qMRMLColorListView Yes check.png
qMRMLColorPickerWidget Znak A-14.png
qMRMLColorTableComboBox Yes check.png
qMRMLColorTableView Yes check.png
qMRMLDisplayNodeWidget Yes check.png
qMRMLEventBrokerWidget Yes check.png
qMRMLLabelComboBox Yes check.png
qMRMLLayoutWidget Znak A-14.png
qMRMLLinearTransformSlider Yes check.png
qMRMLListWidget Yes check.png
qMRMLMatrixWidget Yes check.png
qMRMLNavigationView Yes check.png
qMRMLNodeComboBox Yes check.png
qMRMLRangeWidget Yes check.png
qMRMLROIWidget Yes check.png
qMRMLScalarInvariantComboBox Yes check.png
qMRMLSceneFactoryWidget Yes check.png
qMRMLSceneViewMenu Yes check.png
qMRMLScreenShotDialog Yes check.png
qMRMLSliceControllerWidget Znak A-14.png
qMRMLSliceWidget Znak A-14.png
qMRMLThreeDViewControllerWidget Yes check.png
qMRMLThreeDView Znak A-14.png
qMRMLThreeDWidget Znak A-14.png
qMRMLTransformSliders NA
qMRMLTreeView Znak A-14.png
qMRMLVolumeInfoWidget Yes check.png
qMRMLVolumeThresholdWidget Yes check.png
qMRMLWindowLevelWidget Znak A-14.png

Screenshots