Domanda

Inizierò a implementare alcuni unit test per un codebase che è un mix di C ++ gestito e non gestito. NUnit può hackerarlo con codice non gestito? Esiste un'alternativa migliore?

È stato utile?

Soluzione

È possibile utilizzare NUnit per testare il codice non gestito, ad esempio:

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

    };
}

Altri suggerimenti

NUnit funzionerà bene con codice non gestito fintanto che scrivi i test unitari in C ++ gestito. Il wrapper esterno sarà compatibile con NUnit e potrà accedere alle parti non gestite.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top