Question

I'm writing a C++ wrapper for libpq. However I can't figure out how I should write my unit tests. My initial reaction was to just wrap the libpq interface into something that's mockable, but that kind of defeats the purpose. Has anyone done this before? If so, how?

Was it helpful?

Solution 2

For unit testing, you can mock some of your classes (db connection, query, parameter binder). For larger functional tests you can use a real connection to a test db. Worked well for two libpq C++ wrappers I did a few years back (one for Qt, another for C++/STL).

With regards to libpqxx - it still does not support binary libpq v3 protocol, which in some cases (e.g. import/export large amounts binary data) may be a bottleneck. Other than this, it's pretty straightforward to use and is quite enjoyable.

OTHER TIPS

Don't do that. There's already a C++ wrapper for libpq, called libpqxx.

I'd test using cppunit, with pre- and post- code to initdb and start a new new PostgreSQL cluster given initdb and pg_ctl on the path.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top