VS2012 : Error with unit test : Assert::AreEqual( object, object ) didn't work

前端 未结 2 1300
野趣味
野趣味 2021-01-02 19:58

I come to you for a strange problem when I use the Visual Studio Native Unit Test on VS 2012. I\'ve a Coordinates class like that:

#ifndef COORDINATES_HPP
#d         


        
相关标签:
2条回答
  • 2021-01-02 20:09

    Given the error message, you might try making your operator== more const friendly:

    bool operator==( const Coordinates coordinates ) const;
    
    0 讨论(0)
  • 2021-01-02 20:19

    The error received after creating your assignment operator, ie

    Error 1 error C2338: Test writer must define specialization of ToString for your class class std::basic_string,class std::allocator > __cdecl Microsoft::VisualStudio::CppUnitTestFramework::ToString(const class Core::Coordinates &).

    is related to needing to provide a way for the unit tests to print out the values it expected and received. You do this by creating a template specialization of the ToString function in the Microsoft::VisualStudio::CppUnitTestFramework namespace. For example:

    namespace Microsoft{
        namespace VisualStudio {
            namespace CppUnitTestFramework {
    
                template<>
                static std::wstring ToString<Coordinates>(const Coordinates  & coord) {
                    return L"Some string representing coordinate.";
                }
    
            }
        }
    }
    

    After that, the unit tests should run.

    0 讨论(0)
提交回复
热议问题