views:

34

answers:

1

I want to test portions of a very complex app which includes both a major native Windows component and a substantial WPF GUI. Due to complexities I can't detail, it is impossible to run the native portion independently nor can I isolate the areas I want to test (spare me the lectures, we're talking a huge legacy code base and we do have refactoring plans).

I'm looking for a unit test kit I can invoke on the native side but must be able to run with the app launched with the managed portion initialised. That seems to rule out the run executable feature of the cfix Windows unit test kit. I really like their philosophy, like WinUnit, of using DLL compilation as a way to add the reflective capabilities missing in C++ and gain a more NUnit-like experience.

Ideally, I want something like WinUnit running within the application code and generating an HTML report.

I'm trying to introduce more TDD and having things as lean as possible is important.

A: 

The answer is C++/CLI.

You can use managed code test frameworks such as mbUnit, NUnit and xUnit.Net with C++/CLI code and they work fine. The contents of the tests then call native functions from the native libraries.

There are two minor gotchas:

  1. There's a bug in xUnit.Net that prevents their InlineData attribute being repeated in C++/CLI, as discussed in this question.
  2. You sometimes have to be careful about the working directory of the test runner or to explicitly copy native DLLs as the shadow copy approach some use will only get managed dependencies.
Andy Dent