Fixing error C2338: Test writer must define specialization of ToString<> error
Visual Studio 2012 ships with a new Native C++ test framework. When writing tests and hitting a error message like this:error C2338: Test writer must define specialization of ToString<const 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<SomeType>(const SomeType &).
You will have to impl. support for the missing type, that's easy to fix, just create a new file in your test project and impl. the function. Here is a quick example defining support for the custom type SomeType:
namespace Microsoft
{
namespace VisualStudio
{
namespace CppUnitTestFramework
{
template<> static std::wstring ToString<SomeType>(const SomeType& t) { RETURN_WIDE_STRING(t); }
}
}
}
Enjoy Native Unit testing!
© 2008 - 2012 Marcus Grenängen. Drupal theme by Kiwi Themes.











3 comments
Привет, друзья
Спасибо за чудо))
Error
Thanks for your post, but I get "Error: ToString is not a template." Am I putting this in the wrong place?
Re: Error
Are you working with raw pointers? If so you also need to have have a template specialization for the pointer case. It's hard to know without having a extracted example of what you are trying to do.
To define an overload for a pointer to SomeType you would specify something like:
Post new comment