Automated GUI Testing

The matpigui framework includes a class for unit testing your own GUI called matpguiTest which is a subclass of the matlab xunit test framework which was introduced in R2013a.
This class allows you to:
  • Run tests of your GUI
  • Imitating the user interacting with the GUI through:
    • uicontrol
    • uicontextmenu
    • uimenu
    • and other user interactions with objects. 
This feature allows you to check that the GUI performs as expected, and if you set up enough test methods you can check that when you add new functionality to your GUI you do not break any of the existing capability.
The Working Examples 01 code creates a basic GUI which performs some actions, a unit test was created for this function which logged the all of the tests in full. 

In the test there is 15 tests - all tests were recorded in a PDF using the gui2pdf capability.
Normally when doing tests you are only interested in the tests which fail, the matpiguiTest has the ability to only save the failed tests.  

A modified test function was created which deliberately fails, the pdf which was created in that situation can be found here (it only contains pages linked to the failed test).
These examples are simplistic - but they show the principle that the framework allows you to:
  1. Automate Testing your GUI.
  2. Quickly create tests which can be run automatically and repeatedly.
  3. Check new features doesn't break existing capability.
  4. Log the results to PDF for reference.
To run the tests yourself - download the latest release here, and extract out the files. 

To run the unit test (in R2013a onwards) type:  runtests unitTest_Working_Example_01_PDF

See also this example for testing and GUI with a lot of user interaction dialogs.

For testing - remember that the tests are only as good as the tests which are created.