← Back to team overview

ubuntu-phone team mailing list archive

How to automatically test applications that use orientation/acceleration sensors

 

Hello all,

this is a long-overdue notification that our platform-api now has a
new backend that provides simulated sensors (acceleration, proximity,
light). Of these, our qtubuntu-sensors binding to the QtSensors API
exports the acceleration sensor and builds an orientation sensor from
it, which are the two things that phone apps actually use. With that
you can write automatic tests for the behaviour of your app wrt.
sensor events.

Documentation is at

 http://bazaar.launchpad.net/~phablet-team/platform-api/trunk/view/head:/src/ubuntu/testbackend/README.md

It basically works like that:

 * You define a text file with the desired sensors, their properties,
   and the events that should happen.

 * You install libubuntu-application-api-test1 (make it a test
   dependency), and run your program under this environment:

     UBUNTU_PLATFORM_API_BACKEND=libubuntu_application_api_test.so.1
     UBUNTU_PLATFORM_API_SENSOR_TEST=/path/to/sensor/data/file

 * If your test involves more than one scenario, it is advisable to
   run each of them in a separate subprocess so that events are
   independent from each other. libprocess-cpp provides a nice TESTP_F
   macro for that for gtest, and it's similarly easy to do that in
   Python.

As a real-life (and production) example how this all works with Qt and
gtest, you can look at the qtubuntu-sensor tests:

  http://bazaar.launchpad.net/~phablet-team/qtubuntu-sensors/trunk/files/head:/tests/

These are integration tests that use the QtSensors API (our "official"
Ubuntu SDK API for apps) and test through the qtubuntu-sensors binding
and the user-facing bits of platform-api.

Note that this does not depend on any platform. It works on an x86
desktop just as well as on a phone or in an armhf package build.

The very same approach should work for apps as well.  Please talk to
me if you want to do this and you run into trouble.  There's certainly
lots of stuff that we can simplify or improve (e. g.  providing
higher-level macros in the test sensor format, etc.).

Thanks,

Martin
-- 
Martin Pitt                        | http://www.piware.de
Ubuntu Developer (www.ubuntu.com)  | Debian Developer  (www.debian.org)

Attachment: signature.asc
Description: Digital signature


Follow ups