Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best unit testing tool for a mix of managed and unmanaged C++?

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?

like image 211
Brian Avatar asked Jan 14 '09 16:01

Brian


People also ask

Which tool used for unit testing?

Unit Testing tools are the testing tools such as JUnit, TestNG, NUnit, PHPUnit, etc., which are used to perform unit testing on a specific module of code developed by the application developer.

Which test tool is mainly used by developers?

Unit testing tools are used by the developers to test the source code of the application or to achieve the source code of the application.

What is NUnit testing framework?

NUnit is an open-source unit testing framework for the . NET Framework and Mono. It serves the same purpose as JUnit does in the Java world, and is one of many programs in the xUnit family.


2 Answers

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));
        }

    };
}
like image 135
okutane Avatar answered Oct 17 '22 06:10

okutane


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.

like image 22
plinth Avatar answered Oct 17 '22 08:10

plinth