QtUnit is a unit testing framework, based on CppUnit. It’s pretty easy to set up and use, though the instructions don’t make it obvious exactly what you have to do.

I ended up doing the following, to add tests to kpf:

Created a new directory in kdenetwork/kpf/src, called test.

Unpacked the qtunit distribution in that directory, renamed it to qtunit for ease of access, built the distribution, left it where it was, set my LD_LIBRARY_PATH and PATH to point into its lib and bin dirs respectively.

Created header and source files in there called KPFTestModule.cpp, KPFTestSuite.(cpp|h) and some TestCase-derived classes. I used the files in qtunit/samples/testmodule as, er, samples. I have ByteRangeTest.(cpp|h) and UtilsTest.(cpp|h) as of this article being written.

Created kpf.qpj, using the .qpj in the root of the qtunit distribution package as an example.

Created a Makefile.am, building a shared library and linking to the kpf library and the qtunit library.

Building creates me a shared library which will be loaded by the test runner app.

Created a shell script called runtests.sh, which looks like this:


make && (exec ./qtunit/bin/guitestrunner ./kpf.qpj &)

I then set guitestrunner to run Vim when I double click on an failed test. This opens vim in konsole and goes to the line with the error:


/usr/kde/3.3/bin/konsole -e vim +%l %s%f

I also set guitestrunner to run all tests in the ‘remembered’ project when I start it. Hmm, I wonder if it even recognises the command line parameter pointing to my project? Never mind, it works.

I’m going to have to adjust the Makefile.am to stop the test stuff being built on a normal build, but apart from that I’m basically set up and writing test cases.

I’d like to find a way to make this process easier, but for now I’ll get some work done!

No comments