This is an unfinished article.
Testing is a topical issue in elementary. There are more and more features in the applications, and we can’t test everything by hand. That’s why there may be some regressions when a big merge is done.
Unfortunately, most of the code has not been written with testing in mind, that’s why a unit testing approach is difficult to use. Here is another means, using LDTP: a GUI Automation tool which uses accessibility features to discover the interface.
For instance, let’s write a simple test for Scratch: check wether a file is well saved and that it content is correct.
Beware, erverything is in Python.
Unit testing in Python
Everything is already included in standard Python libraries for unit testing.
Here is a stub we are going to use:
import unittest class ScratchSave(unittest.TestCase): def setUp(self): pass def test_save(self): pass if __name__ == '__main__': unittest.main()
Let’s see some LDTP related code to launch Scratch and get a window object:
import ldtp, ooldtp ldtp.launchapp('scratch-text-editor') window = ooldtp.context('*Scratch') window.waittillguiexist() print window.getobjectlist()
When this code is executed, we get:
['flr8', 'flr4', 'flr5', 'flr6', 'flr7', 'flr0', 'flr1', 'flr2', 'flr3', 'btnSave', 'btnOpenfile', 'tbar0', 'lblOpenafiletobeginediting', 'ptl0', 'lblNofilesareopen', 'splt2', 'splt0', 'btnNewdocument', 'btnRevert', 'tbar1', 'pnl6', 'pnl7', 'pnl4', 'pnl5', 'pnl2', 'pnl3', 'pnl0', 'btnOpen', 'tbtn1', 'tbtn0', 'frmScratch', 'ptl1', 'pnl8', 'pnl9', 'btnUndo', 'btnRedo', 'pnl1', 'btnNewfile', 'ptl2', 'splt1', 'pnl10', 'pnl11']
Then we want to get a button to click it:
window.getchild("btnNewdocument").click()