c++ - Microsoft Visual Studio 单元测试的 C2338 编译错误

标签 c++ windows unit-testing visual-studio-2013 vs-unit-testing-framework

当我尝试在 Visual Studio 2013 中编译单元测试时收到以下错误:

Error 1 error C2338: Test writer must define specialization of ToString<Q* q> for your class class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > __cdecl Microsoft::VisualStudio::CppUnitTestFramework::ToString<struct HINSTANCE__>(struct HINSTANCE__ *).

您可以通过如下测试方法重现错误:

const std::wstring moduleName = L"kernel32.dll";
const HMODULE expected = GetModuleHandle(moduleName.c_str());
Microsoft::VisualStudio::CppUnitTestFramework::Assert::AreEqual(expected, expected);

有谁知道我需要如何编写这样一个 ToString 的特化?

最佳答案

我在比较类对象时遇到了同样的问题。 对我来说,我可以通过简单地写来解决它

Assert::IsTrue(bitmap1 == bitmap2);

代替

Assert::AreEqual(bitmap1, bitmap2);

关于c++ - Microsoft Visual Studio 单元测试的 C2338 编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28739852/

相关文章:

c++ - 将迭代器用作参数时在内部增加迭代器是否安全?

windows - 示例代码 : A service calls CreateProcessAsUser() I want the process to run in the user's session, 不是 session 0

c++ - windbg中 "Internal"输出中的 "!heap -h"是什么意思?

java - 如何对void方法进行白盒测试?

iphone - iOS:Sqlite 的单元测试

c++ - 当作为参数传递的对象超出范围时,析构函数是否会调用自身?

c++ - 为什么循环摘要在 gprof 的调用图输出中没有任何调用者?

c++ - 如何将文本文件编译为 C++ 程序作为 const 字符串?

c++ - LLVM:VS 2015中的链接错误

java - 打破本地依赖以单元测试无效方法