Unit Testing for GUI

Sikuli is designed to support unit testing for GUI by integrating with junit. The unit testing panel can be opened by clicking on View/Unit Test or by shortcut Cmd-U on Mac (or Ctrl-U on Windows/Linux).

Sikuli IDE aims to minimize the effort of writing code. With Sikuli IDE, a Python class inherited from junit.framework.TestCase is automatically generated to wrap the unit testing script.

A typical unit testing script consists of two constructing and destructing methods, setUp() and tearDown(), and a bunch of methods named with a prefix "test". Two specific Sikuli functions for testing are available: assertExist() and assertNotExist(), that raise an AssertionError if pattern or image is not found or found respectively. (Details:  Command Reference )

The basic structure of a script is given as following:

def setUp(self):
  openApp("AnyRandom.app")
  wait(SCREENSHOT_OF_THE_APP) # wait until the app appears

def tearDown(self):
  closeApp("AnyRandom.app")
  untilNotExist(SCREENSHOT_OF_THE_APP) # wait until the app disappears

def testA(self):
  ....
  assertExist(PICTURE_THAT_SHOULD_BE_THERE)

def testB(self):
  ....
  assertNotExist(PICTURE_THAT_SHOULD_NOT_BE_THERE)

 Here you have a real example with the Application jEdit.

To run a unit testing script, you need to click on the run button in the unit testing panel instead of the ordinary button. Be sure to save the script before the first test run and after every change.