对于托管和非托管 C++ 组合来说,最好的单元测试工具是什么?

发布于 2024-07-11 23:50:42 字数 69 浏览 6 评论 0原文

我将开始为托管和非托管 C++ 混合的代码库实现一些单元测试。 NUnit 可以用非托管代码破解它吗? 有更好的选择吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

绳情 2024-07-18 23:50:42

可以使用 NUnit 来测试非托管代码,例如:

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

    };
}

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

    };
}
青衫负雪 2024-07-18 23:50:42

只要您使用托管 C++ 编写单元测试,NUnit 就可以很好地处理非托管代码。 外部包装器将是 NUnit 友好的,并且可以访问非托管部分。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文