当前位置: 动力学知识库 > 问答 > 编程问答 >

c++ - libpq - writing tests

问题描述:

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?

网友答案:

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.

网友答案:

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.

分享给朋友:
您可能感兴趣的文章:
随机阅读: