我有一个std::vector<Token> tokenize(const std::string& s)
要进行单元测试的功能。该Token
结构定义如下:
enum class Token_type { plus, minus, mult, div, number };
struct Token {
Token_type type;
double value;
}
我已经设置了 CppUnitTest 并且可以进行玩具测试,例如1 + 1 == 2
运行。但是当我尝试对我的tokenize
函数运行测试时,它给了我这个错误:
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<class std::vector<struct Token,class std::allocator<struct Token> >>(const class std::vector<struct Token,class std::allocator<struct Token> > &).
我的测试代码是这样的:
#include <vector>
#include "pch.h"
#include "CppUnitTest.h"
#include "../calc-cli/token.hpp"
using namespace std;
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
namespace test_tokens {
TEST_CLASS(test_tokenize) {
public:
TEST_METHOD(binary_operation_plus) {
auto r = tokenize("1+2");
vector<Token> s = {
Token{ Token_type::number, 1.0 },
Token{ Token_type::plus },
Token{ Token_type::number, 2.0}
};
Assert::AreEqual(r, s);
}
};
}
是什么导致了错误,我该如何解决?