annotate content/Coding/004-fructose-contrib.rst @ 5:4b5cdcc351c5

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