D-Bus和HAL的单元测试?

时间:2021-03-27 16:13:09

How does one test a method that does some interactions with the local D-Bus (accessing a HAL object)?

如何测试与本地D-Bus进行某些交互(访问HAL对象)的方法?

Results of tests will differ depending on the system that the test is run on, so I don't know how to provide the method reliable input.

测试结果将根据运行测试的系统而有所不同,因此我不知道如何提供方法可靠的输入。

I'm working in Python, by the way.

顺便说一下,我正在使用Python。

2 个解决方案

#1


If you can not mock the environment then it's probably impossible for you to write the test. If your access to HAL/D-Bus is via an object and you provide a mock instance to your test then it should be possible to emulate the necessary inputs to your test from the mock implementation.

如果你不能模仿环境,那么你可能无法编写测试。如果您通过对象访问HAL / D-Bus并且您为测试提供了一个模拟实例,那么应该可以从模拟实现模拟测试的必要输入。

#2


It's also possible to create a temporary D-Bus buses for tests, and emulate any services your program uses in your test code. You can use this approach for programs which are D-Bus services, D-Bus clients, or both. The downside is that the bus setup is a bit hairy. There's code for doing this in e.g. Telepathy Gabble.

也可以为测试创建临时D-Bus总线,并模拟程序在测试代码中使用的任何服务。您可以将此方法用于D-Bus服务,D-Bus客户端或两者的程序。缺点是总线设置有点毛茸茸。有这样的代码,例如:心灵感应加布尔。

#1


If you can not mock the environment then it's probably impossible for you to write the test. If your access to HAL/D-Bus is via an object and you provide a mock instance to your test then it should be possible to emulate the necessary inputs to your test from the mock implementation.

如果你不能模仿环境,那么你可能无法编写测试。如果您通过对象访问HAL / D-Bus并且您为测试提供了一个模拟实例,那么应该可以从模拟实现模拟测试的必要输入。

#2


It's also possible to create a temporary D-Bus buses for tests, and emulate any services your program uses in your test code. You can use this approach for programs which are D-Bus services, D-Bus clients, or both. The downside is that the bus setup is a bit hairy. There's code for doing this in e.g. Telepathy Gabble.

也可以为测试创建临时D-Bus总线,并模拟程序在测试代码中使用的任何服务。您可以将此方法用于D-Bus服务,D-Bus客户端或两者的程序。缺点是总线设置有点毛茸茸。有这样的代码,例如:心灵感应加布尔。