TimedActionFixture for C++

Fitnesse is a very useful tool for defining acceptance tests and verifying them against your application code.  Fitnesse is available for different languages, among them, Java, the .NET runtime and C++.

Unfortunately, the C++ version of Fitnesse has lagged a bit behind in features compared to its Java and .NET cousins.

One useful fixture missing from C++ is the TimedActionFixture.  A need presented itself at work one time, so I wrote a C++ version on my own time (since the effort wasn't covered by any of our stories in the current iteration).

The nice thing about this fixture is that it is a drop-in replacement for the standard ActionFixture.  If you have an existing test table using the ActionFixture, you merely rename it!

Here is the source code:


#include "ActionFixture.h"

class TimedActionFixture : public ActionFixture


   void doTable(ParsePtr table);
   void doCells(ParsePtr cells);

   ParsePtr td(std::string body);


#include <time.h>
#include <assert.h>
#include "TimedActionFixture.h"

TimedActionFixture::TimedActionFixture() : ActionFixture()


void TimedActionFixture::doTable(ParsePtr table)

   table->parts->parts->last()->more = td(std::string("startTime"));
   table->parts->parts->last()->more = td(std::string("seconds"));

void TimedActionFixture::doCells(ParsePtr cells)
   bool bClockError = false;

   time_t  start;
   ::time( &start );

   clock_t cStart = clock();
   if ( cStart == (clock_t)-1 )
      bClockError = true;


   time_t  now;
   ::time( &now );
   struct tm *tstart = localtime( &start );

   clock_t cNow = clock();
   if ( cNow == (clock_t)-1 )
      bClockError = true;

   char buf[100];

   double split = (double)(cNow - cStart) / CLOCKS_PER_SEC;

   if ( bClockError )
      strcpy( buf, "Elapsed time unavailable" );
      sprintf( buf, "%.3lf", split );

   cells->last()->more = td( std::string(asctime( tstart )) );
   cells->last()->more = td( std::string(buf) );

ParsePtr TimedActionFixture::td(std::string body)
   Parse *p = new Parse("td", body, 0, 0);
   return( p );

The last piece needed is the "hook" to register the new fixture like a standard fixture.  This can be done with the following lines of code in the method DynamicMaker::makeStaticFixture() found in DynamicMaker.cpp

    if (name == "TimedActionFixture")
        return new TimedActionFixture;

Print | posted on Saturday, March 29, 2008 11:29 AM


# re: TimedActionFixture for C++

Left by vjr at 9/15/2009 4:39 PM
Gravatar Only 18 months after the fact, but well done, haven't used it yet but any contributions to the C++ fitnesse effort is to be applauded. Still looking for more Fitnesse resources...

Your comment:


Copyright © Stephen Cebula

Design by Bartosz Brzezinski

Design by Phil Haack Based On A Design By Bartosz Brzezinski