Search code examples
c++visual-studiocharwchar-tmicrosoft-unit-testing

C++ use Assert::AreEqual string and string


I use the Microsoft Unit Testing for C++, but when I use Assert::AreEqual comparing string and the string contains Chinese words. The Test Explorer display unrecognizable characters.

using namespace Microsoft::VisualStudio::CppUnitTestFramework;

namespace tests
{
    using std::string,std::wstring;
    TEST_CLASS(Test)
    {
    public:
        TEST_METHOD(test)
        {
            Assert::AreEqual("测试", "测试1");
        }
    };
}

unrecognizable characters

If I should use converter to change the string or char* to wstring or wcahr_t*?

using namespace Microsoft::VisualStudio::CppUnitTestFramework;

namespace tests
{
    using std::string,std::wstring;
    TEST_CLASS(Test)
    {
    public:
        TEST_METHOD(test)
        {
            Assert::AreEqual(L"测试", L"测试1");
        }
    };
}

recognizable characters

Thanks in advance.


Solution

  • It fails to display the correct character set but does not affect the results.

    For displaying Chinese, you need to use wide characters.