Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Introduzione ad Autopilot
1. Unity, testing with Autopilot
Quality is the Word!
Ubuntu-it meeting 2012
Marco Trevisan (Treviño) – marco@ubuntu.com
2. Unity, testing with Autopilot
Setting up your system
# Download del codice sorgente di unity
$ bzr branch lp:unity
# Installazione pacchetti necessari
$ sudo apt-get install python-autopilot
# Testare codice on-the-edge
$ sudo add-apt-repository
ppa:unity-team/staging
Ubuntu-it meeting 2012
Marco Trevisan (Treviño) – marco@ubuntu.com
3. Unity, testing with Autopilot
Running the tests
# Entrare nella directory di unity
$ cd ~/my-source-code/unity
# Esportare la variabile PYTHONPATH
$ export PYTHONPATH=$PWD/tests/autopilot
# Avviare i test
$ autopilot run unity
# Avviare un test specifico
$ autopilot run
unity.tests.test_panel.PanelIndicatorEntry*
Ubuntu-it meeting 2012
Marco Trevisan (Treviño) – marco@ubuntu.com
4. Unity, testing with Autopilot
Inspecting Unity
$ autopilot vis
Ubuntu-it meeting 2012
Marco Trevisan (Treviño) – marco@ubuntu.com
5. Unity, testing with Autopilot
Test Example
// Inherit from unity::debug::Introspectable
void PanelIndicatorEntryView::AddProperties(GVariantBuilder* builder)
{
variant::BuilderWrapper(builder)
.add(GetAbsoluteGeometry())
.add("entry_id", GetEntryID())
.add("name_hint", entry_->name_hint())
.add("type", entry_->type_name())
.add("priority", entry_->priority())
.add("label", GetLabel())
.add("label_sensitive", IsLabelSensitive())
.add("label_visible", IsLabelVisible())
.add("icon_sensitive", IsIconSensitive())
.add("active", proxy_->active())
.add("menu_x", proxy_->geometry().x)
.add("menu_y", proxy_->geometry().y));
// ecc...
}
Ubuntu-it meeting 2012
Marco Trevisan (Treviño) – marco@ubuntu.com
6. Unity, testing with Autopilot
Test Example
def test_menu_opens_on_click(self):
"""Tests that clicking on a menu entry, opens a menu."""
self.open_new_application_window("Calculator")
refresh_fn = lambda: len(self.panel.menus.get_entries())
self.assertThat(refresh_fn, Eventually(GreaterThan(0)))
menu_entry = self.panel.menus.get_entries()[0]
self.mouse_open_indicator(menu_entry)
self.assertThat(menu_entry.active, Eventually(Equals(True)))
self.assertThat(menu_entry.menu_x, Eventually(Equals(menu_entry.x)))
self.assertThat(menu_entry.menu_y, Eventually(Equals(self.panel.height)))
def mouse_open_indicator(self, indicator):
"""This is an utility function that safely opens an indicator."""
if not isinstance(indicator, IndicatorEntry):
raise TypeError("Window must be a IndicatorEntry")
indicator.mouse_click()
self.addCleanup(self.panel.move_mouse_below_the_panel)
self.addCleanup(self.keyboard.press_and_release, "Escape")
self.assertThat(indicator.active, Eventually(Equals(True)))
Ubuntu-it meeting 2012
Marco Trevisan (Treviño) – marco@ubuntu.com
7. Unity, testing with Autopilot
RTFM!
Documentazione e tutorial:
●
http://unity.ubuntu.com/autopilot/
●
https://wiki.ubuntu.com/Unity/QA/Autopilot
Ubuntu-it meeting 2012
Marco Trevisan (Treviño) – marco@ubuntu.com
8. Unity, testing with Autopilot
Question time
GRAZIE!
Ping me: Trevinho @ Freenode
Ubuntu-it meeting 2012
Marco Trevisan (Treviño) – marco@ubuntu.com