Sikuli IDE旨在尽力减少代码输入,所以在Sikuli IDE中,一个继承自junit.framework.TestCase的Python类会自动生成并把你的单元测试脚本包起来。
通常,一个单元测试脚本包含有构造和析构函数,分别是setUp()和tearDown(),还包含一堆以test为前缀的测试方法。
单元测试脚本的基本结构如下:
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): .... assert exists(PICTURE_THAT_SHOULD_BE_THERE) def testB(self): .... assert not exists(PICTURE_THAT_SHOULD_NOT_BE_THERE)
要运行单元测试脚本,需要点击单元测试面板上的“Run”按钮,而不是普通的运行按钮。
另外,也可能从命令行使用选项 -t test-script来运行单元测试脚本。