我有以下枚举:
namespace Country {
enum {
ITALY = 1,
SPAIN = 2
};
}
以及以下 UnitTest++ 测试:
TEST(something) {
CHECK_EQUAL(Country::SPAIN, object.getCountry(1)); // getCountry returns int
}
这行不通。我以为 Country::SPAIN
会自动转换为 int 2,但我得到了这个错误:
error: no matching function for call to ‘CheckEqual(UnitTest::TestResults&, Country::<anonymous enum>, int, UnitTest::TestDetails)’
最佳答案
自己将枚举转换为 int
:
TEST(something) {
CHECK_EQUAL(static_cast<int>(Country::SPAIN), object.getCountry(1));
}
关于c++ - 如何将 C++ 枚举与 UnitTest++ 检查一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5480190/