Tests don't test what you think they're testing.
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
libfriends |
Fix Released
|
High
|
Ken VanDine |
Bug Description
Ok, so I'm just analyzing the compiler warnings and trying to clean stuff up, when I was confronted with this little curio:
test-service.
test-service.
test-service.
test-service.
test-service.
test-service.
test-service.
test-service.
Upon further investigation, it makes sense: The methods being tested catch those exceptions themselves, and the compiler is correctly identifying that these catch blocks can literally never be triggered under any circumstances. This makes the testsuite effectively *tautological*: We run a method that can't fail, then we set a variable to true, then we assert that the true value is true. There is simply no possible condition under which this test can fail, even if the libfriends code that it purportedly tests is utterly broken, the test will still pass.
What we *really* need to be doing in this testsuite is as simple as confirming that the vala methods are invoking the dbus methods. That's literally all that needs to get done (because all the *real* functionality is already implemented and tested on the python side). I scoured through the dbusmock documentation, and it seems that dbusmock unfortunately does not provide any kind of dbus method that could be considered comparable to python's mock.assert_
So how do we go about confirming that methods have been called? Well, in pitti's official documentation, he says that all mocked dbus methods spew out their call signature on STDOUT, and indeed all the official examples demonstrate diverting STDOUT into a special log, that is then searched for the expected textual output.
Unfortunately I don't know enough about vala to do this STDOUT redirection myself (all of the examples given were pure python only), but sure enough in the 'make check' output you can clearly *see* this logging output:
DBus daemon: unix:abstract=
DBusService: Started with PID: 31108
Service : Started with PID: 31112
Activating service name='org.a11y.Bus'
Successfully activated service 'org.a11y.Bus'
Activating service name='org.
Service : /Unit/Friends/
DBusService: 1357954200.392 Refresh
Service : /Unit/Friends/
DBusService: 1357954200.398 Quit
Service : /Unit/Friends/
Service : /Unit/Friends/
DBusService: 1357954200.404 GetFeatures "twitter"
DBusService: 1357954200.417 SendMessage "A message"
Service : /Unit/Friends/
DBusService: 1357954200.423 Do "send" "1" "A message"
Service : /Unit/Friends/
DBusService: 1357954200.428 SendReply "A message" "1" "100"
Service : /Unit/Friends/
Service : /Unit/Friends/
DBusService: 1357954200.433 ClearIndicators
DBusService: 1357954200.439 URLShorten "http://
Service : /Unit/Friends/
Service : /Unit/Friends/
Service : /Unit/Friends/
Service : /Unit/Friends/
DBusService: Shutting down
Service: Shutting down
DBus daemon: Shutdown
PASS: test-runner
So Ken, I'm gonna need you to modify the testrunner to divert STDOUT into some kind of buffer that is accessible to the testsuite, and then all the calls to `assert(success == true)` are gonna need to be changed to something more along the lines of asserting that the above log lines appear in the diverted log output.
Hope this makes sense! Let me know if you need to know anything else to fix this.
Related branches
- Martin Pitt: Approve
- Robert Bruce Park (community): Approve
-
Diff: 105 lines (+70/-0)2 files modifieddbusmock/mockobject.py (+23/-0)
tests/test_api.py (+47/-0)
Changed in libfriends: | |
status: | Triaged → Fix Released |
Actually I think the problem is the functions being tested need to not only catch the error but also throw an error for the tests or clients to catch.