How to make automated tests for clients of D-Bus system service?

Miroslav Kravec kravec.miroslav at gmail.com
Tue Feb 6 13:32:49 UTC 2018


On Tue, Feb 6, 2018 at 1:31 PM, Simon McVittie <smcv at collabora.com> wrote:
> ...
>
> Or if you want a little more detail than that, the standard procedure is:
>
> * Run a dbus-daemon that you will pretend is the system bus, and capture
>   its address (use the --print-address option)

How do I start own dbus-daemon? Following command fails:

```
$ dbus-daemon --print-address
No configuration file specified.
dbus-daemon [--version] [--session] [--system] [--config-file=FILE]
[--print-address[=DESCRIPTOR]] [--print-pid[=DESCRIPTOR]]
[--introspect] [--address=ADDRESS] [--nopidfile] [--nosyslog]
[--syslog] [--syslog-only] [--nofork] [--fork] [--systemd-activation]
```

> * Put a mock implementation of your system service on that bus (write it
>   however you like, but python-dbusmock is one option)
> * Run your client with the environment variable DBUS_SYSTEM_BUS_ADDRESS
>   set to the address where your fake system bus is listening
>
> This is a lot like the procedure for testing session bus clients, but
> with fake system services and a fake system bus instead of their session
> bus counterparts.

This sounds to be exactly what I need. Tool/library python-dbusmock
seems to be useful. It's packaged in Debian
(https://packages.debian.org/sid/python-dbusmock) and Fedora
(https://apps.fedoraproject.org/packages/python-dbusmock), and that
makes it viable option.

> If you're using GDBus, look at GTestDBus for inspiration (but you don't
> necessarily want to *use* GTestDBus, because it has some design issues
> around the lifetimes of the singleton shared bus connections vs. the
> lifetime of a test fixture).
>
> If you're using libdbus, (a) consider doing something else, or (b) take
> a look at test/test-utils-glib.[ch] or tools/dbus-run-session.c in dbus
> for inspiration.

I'm looking for the most simple way to do it. Python should be enough.
I don't really care about performance and memory consumption of
automated tests. I focus more on end-user experience, and fast
development, as the project I'm working on is small, and with limited
development capacity.


More information about the dbus mailing list