rdit-ch / itemframework

A Qt-based application framework that allows users to define units and control the flow of data between them.
https://rdit.ch
8 stars 9 forks source link

Testing infrastructure #23

Closed fschlaepfer closed 7 years ago

fschlaepfer commented 7 years ago

This PR adds basic unit testing infrastructure to the itemframework.

In order to separate the itemframework implementation from the unit tests, the itemframework project has been split into two separate subdir projects. The new folder structure looks as follows (assuming the repository has been checked out under a folder named itemframework):

itemframework/
itemframework/itemframework.pro
itemframework/itemframework
itemframework/itemframework/itemframework.pro
itemframework/itemframework/...
itemframework/tests
itemframework/tests/tests.pro
itemframework/tests/...

Tests are built separately from the framework under tests/build.

Note that this requires applications using the itemframework to be updated accordingly, with the new correct path to the itemframework folder. In particular, the paths to {plugin,starter,usercore}.pri must be updated. The itemframework-example project will be updated to reflect these changes.

In order to test classes that rely on modules such as QtGui, a new headless mode has been added to the GuiManager class, which allows an itemframework application to be run non-interactively. This mode initializes the necessary environment to test these classes without prompting the user to select a workspace, for example. For details on how to use it, see the included sample test cases.

As an example, tests for the two member functions loadFromXml and saveToXml of the ItemScene class are included. Note that these two member functions are private. In order to be able to test them, they are temporarily made public with this PR. These member functions were chosen because an upcoming PR will refactor these methods and eventually move them into a separate class, which will expose them as its public interface and can then be tested independently from the ItemScene class.

t-moe commented 7 years ago

In order to test classes that rely on modules such as QtGui, a new headless mode has been added to the GuiManager class, which allows an itemframework application to be run non-interactively. This mode initializes the necessary environment to test these classes without prompting the user to select a workspace, for example. For details on how to use it, see the included sample test cases.

Which classes really require QApplication ? My initial idea was to use the Q_CLASSINFO("guiModule",true) lines to mark Singletons for gui/non-gui mode. In this commit I dont't see any class which need the GuiManager or any Gui Class. So it should be possible to test them with a QCoreApplication and therefore the GuiManager would never be constructed. In this context I don't see any usecase for GuiManager::setMode. But maybe I missed something?