'Best approach to mock hiredis library in C
I am writing a project that takes advantage of the hiredis redis client library.
What is the best approach to mock this library for use in writing tests?
For example, I would like the ability to write tests that verify certain behavior when redis is no longer available, or when it has a certain dataset in it, that my application behaves properly.
The thought of trying to script all of this into starting/shutting down various redis instances that the test code can use seems tedious and not very elegant.
I have looked a bit at cmock, but it seems very complicated, but maybe this is the standard?
Thanks for any light anyone can shed~
Solution 1:[1]
I'd say that this falls under the category of 'integration testing', as it is really testing how your application integrates with redis. If you're doing proper unit tests, they shouldn't touch redis anyway, and your redis-interfacing code should be well separated from the important testable stuff.
So I'd say bite the bullet and automate the redis server.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Joe |