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