NUnit与混合代码DLL

时间:2013-10-09 08:22:31

标签: c++ unit-testing nunit managed

我想用NUnit测试我的混合代码C ++ dll(/ clr),我已经创建了一个项目 用于测试但有链接器错误:

error LNK2028: unresolved token (0A00057B) "public: __thiscall UtilityFunctions::UtilityFunctions(void)" (??0UtilityFunctions@@$$FQAE@XZ) referenced in function "public: __clrcall TestUtilityFunctions::TestUtilityFunctions(void)" (??0TestUtilityFunctions@@$$FQ$AAM@XZ)
error LNK2028: unresolved token (0A00057C) "public: int __thiscall UtilityFunctions::StringToInt(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &)" (?StringToInt@UtilityFunctions@@$$FQAEHAAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "public: void __clrcall TestUtilityFunctions::Test_StringToInt(void)" (?Test_StringToInt@TestUtilityFunctions@@$$FQ$AAMXXZ)

- &GT;在UnitTest dll中添加要测试的混合模式dll作为参考

TestUtilityFunctions.h

#include <string>
#include <sstream>
#include <msclr/marshal.h>
#include <msclr/marshal_cppstd.h>

using namespace System::Text;
using namespace System::Collections::Generic;
using namespace msclr::interop;
using namespace NUnit::Framework;

using namespace IsoModuleTest;

using namespace std;

#pragma unmanaged
#include "UtilityFunctions.h"
#pragma managed

[TestFixture]
public ref class TestUtilityFunctions
{
public:
    TestUtilityFunctions()
    {   
        m_utilFunctions = new UtilityFunctions();
    }
    ~TestUtilityFunctions()
    {
        delete m_utilFunctions;
    }

    [Test]
    void Test_StringToInt()
    {                           
        Assert::AreEqual(m_utilFunctions->StringToInt((std::string)"12"), 12);
    }
private:    
    UtilityFunctions *m_utilFunctions;
};

此处需要采取其他措施或出现什么问题?

THX!

0 个答案:

没有答案