views:

291

answers:

2

I am going to start implementing some unit tests for a codebase that is a mix of managed and unmanaged C++. Can NUnit hack it with unmanaged code? Is there a better alternative?

+3  A: 

It's possible to use NUnit to test unmanaged code, example:

// Tests.h

#pragma once

#include <cmath>

using namespace System;
using namespace NUnit::Framework;

namespace Tests {

    [TestFixture]
    public ref class UnitTest
    {
    public:
     UnitTest(void) {}

     [Test]
     void TestCos()
     {
      Assert::AreEqual(1, cos(0.0));
     }

    };
}
Dmitriy Matveev
+1  A: 

NUnit will work fine with unmanaged code as long as you write the unit tests in managed C++. The outside wrapper will be NUnit friendly and can access the unmanaged parts.

plinth