Using unit test feature and the alternatives
- Keywords:
- Last updated by:
- RaiMan
For the basics on the following examples have a look at the docs at
http://
*** backport unittest2
There is a package unittest2 available in the net, that makes it possible to use features from 2.6 and 2.7 (e.g. skip tests) in Python prior versions. Since it is written in Python language only, it can be used with Sikuli.
**** a template for unit test cases separated in .sikuli scripts
(you might put everything in one script as well ;-)
--- in each of your modUnitTestx.sikuli
at the beginning of each script put:
from sikuli import *
import unittest
class UnitTestX(
indent the rest of the script one level, so that all the def's belong to your TestCase class.
In this class put a bunch of "def testxxxx(self):" and may be setUp and tearDown.
so for this example you might have:
# script modUnitTestA.sikuli
class UnitTestA(
def setUp(self):
def test1(self):
def test2(self):
def test3(self):
def tearDown(self):
--- create a mainTest.sikuli
as a base template, to get a feeling:
import unittest
from modUnitTestA import * # supposing, scripts live in same directory
suite = unittest.
unittest.
-- comment
loads all def()'s from class UnitTestA which is in modUnitTestA.
**** a test runner, that produces HTML output
see: https:/
I have a modified version, that stores a screenshot on failure, that you can look at with a link in the HTML result page.
import HTMLTestRunner
... since it is bundled with SikuliX in version 1.1.x
**** a tip for Hudson/Jenkins (from: https:/
I recommend Jython/Python unittests instead of the sikuli-special version.
I use an Python TestRunner that outputs JUnit-XML testresultfiles that can e.g. be used by Hudson/Jenkins.
XMLTestRunner1 (v. 0.1) and XMLTestRunner (v. 0.2) are bundled with SikuliX 1.1.x
Find out which one suits you best
You can use it like this:
from XMLTestRunner1 import * # or XMLTestRunner2
import unittest
class MyTest(
def setUp(self):
// setUp
def testMyTest(self):
// test
def tearDown(self):
// tearDown
suite = unittest.
result = XMLTestRunner(
**** Sikuli and RobotFrameWork
for SikuliX 1.1.x see:
http://
for older versions of SikuliX:
http://