bgneal@4: I contributed to Fructose bgneal@4: ######################### bgneal@4: bgneal@4: :date: 2011-05-31 21:40 bgneal@4: :tags: Fructose, C++, Python, UnitTesting bgneal@4: :slug: i-contributed-to-fructose bgneal@4: :author: Brian Neal bgneal@4: bgneal@4: At work we started using CxxTest_ as our unit testing framework. We like it because bgneal@4: it is very light-weight and easy to use. We've gotten a tremendous amount of benefit bgneal@4: from using a unit testing framework, much more than I had ever imagined. We now have bgneal@4: almost 700 tests, and I cannot imagine going back to the days of no unit tests or ad-hoc bgneal@4: testing. It is incredibly reassuring to see all the tests pass after making a significant bgneal@4: change to the code base. There is no doubt in my mind that our software-hardware integration bgneal@4: phases have gone much smoother thanks to our unit tests. bgneal@4: bgneal@4: Sadly it seems CxxTest is no longer actively supported. However this is not of great bgneal@4: concern to us. The code is so small we are fairly confident we could tweak it if necessary. bgneal@4: bgneal@4: I recently discovered Fructose_, a unit testing framework written by Andrew Marlow. It too bgneal@4: has similar goals of being small and simple to use. One thing I noticed that CxxTest had that bgneal@4: Fructose did not was a Python code generator that took care of creating the ``main()`` function bgneal@4: and registering all the tests with the framework. Since C++ has very little introspection bgneal@4: capabilities, C++ unit testing frameworks have historically laid the burden of registering bgneal@4: tests on the programmer. Some use macros to help with this chore, but littering your code bgneal@4: with ugly macros makes tests annoying to write. And if anything, you want your tests to be bgneal@4: easy to write so your colleagues will write lots of tests. CxxTest approached this problem by bgneal@4: providing first a Perl script, then later a Python script, to automate this part of the process. bgneal@4: bgneal@4: I decided it would be interesting to see if I could provide such a script for Fructose. After bgneal@4: a Saturday of hacking, I'm happy to say Andrew has accepted the script and it now ships with bgneal@4: Fructose version 1.1.0. I hope to improve the script to not only run all the tests but to also bgneal@4: print out a summary of the number of tests that passed and failed at the end, much like CxxTest does. bgneal@4: This will require some changes to the C++ code. Also on my wish list is to make the script bgneal@4: extensible, so that others can easily change the output and code generation to suit their needs. bgneal@4: bgneal@4: I've hosted the code for the Python script, which I call ``fructose_gen.py`` on Bitbucket_. bgneal@4: Feedback is greatly appreciated. bgneal@4: bgneal@4: .. _CxxTest: http://cxxtest.tigris.org/ bgneal@4: .. _Fructose: http://fructose.sourceforge.net/ bgneal@4: .. _Bitbucket: https://bitbucket.org/bgneal/fructose_gen/src