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