我想用 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)
-> 在 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;
};
这里需要任何其他步骤或有什么问题吗?
谢谢!