Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to incorporate Fitnesse into C++ code?

I'm trying to use Fitnesse to interface with some C++ code, but the Fit Cpp project file provided on the fitnesse.org website doesn't work (it's VC++ 6 which I don't have but I do have Visual Studio 2005 and 2008). I can't even seem to open the solution file in VS2005 or VS2008 (maybe because it was created in VC++ 6?).

Has anyone been able to get this working? Is there a way I can write a test fixture in C# that communicates with the C++ code? If so, how do I go about doing this.

Here is the website with the code: http://fitnesse.org/FrontPage.FitServers.CppFit.CppTestTools.SetUpCppTestTools

Ideally, I would like to be able to work on this in Visual Studio and avoid cygwin. Should I just bite the bullet and go with cygwin ... not sure that will even work either ... haven't tried.

Any help will be much appreciated. Thanks in advance.

like image 442
Brian T Hannan Avatar asked Oct 06 '11 15:10

Brian T Hannan


1 Answers

Using C++/CLI is one option. That way you can use fitSharp as the bridge from FitNesse to your fixture code, but your fixture code can call directly into C++.

Here's a simple example of testing a Calculator class. First, here's the C++ code we want to test:

class Calculator
{
  public:
    int Add(int x, int y)
    {
      return x + y;
    }
};

and here's the C++/CLI fixture code:

public ref class CalculatorFixture
{
  public:
    property int X;
    property int Y;
    property int Z;

    void Execute()
    {
      Calculator calculator;
      Z = calculator.Add(X,Y);
    }
};

The FitNesse wiki page would look like this:

!define TEST_SYSTEM {slim}
!define COMMAND_PATTERN {%m -r fitSharp.Slim.Service.Runner,C:\fitnesse\fitsharp\fitsharp.dll %p}
!define TEST_RUNNER {C:\fitnesse\fitsharp\Runner.exe}

!path c:\CalculatorFixture.dll

!|CalculatorFixture|
|X         |Y         |Z?        |
|2         |2         |4         |
|3         |4         |7         |

One issue to watch out for is that C++/CLI DLLs are generally either 32-bit or 64-bit, whereas the fitSharp runner is 'any cpu'. So if you build your C++/CLI DLL as 32-bit and try to use fitSharp with it on a 64-bit OS, you'll get an 'incorrect format' error. In that case either build the C++/CLI DLL as 64-bit, or use corflags to force the fitsharp runner (Runner.exe) to be 32-bit.

like image 66
Andy Avatar answered Sep 20 '22 14:09

Andy