I am trying to do a unit test on some c++ code but am running into some trouble.
I have something similar to the following lines of code...
std::string s1 = obj->getName();
std::string s2 = "ExpectedName";
Assert::AreEqual(s1, s2, "Unexpected Object Name");
And I'm getting the following compiler error...
error C2665: 'Microsoft::VisualStudio::TestTools::UnitTesting::Assert::AreEqual' :
none of the 15 overloads could convert all the argument types
It seems like it should be a match with the following overload:
AreEqual<(Of <(T>)>)(T, T, String)
Isn't the above overload a template overload that should support any object, as long as arguments 1 and 2 are of the same type? Or am I missing something?
Is there some other way that I can accomplish this Assert?
You're attempting to use the managed unit testing framework with native types – this simply isn't going to work without marshaling the objects into managed types first.
VS2012 now comes with a native C++ unit testing framework; using this framework instead, your code could work by changing "Unexpected Object Name"
to a wide string (prefix with L
) and calling the following overload:
template<typename T>
static void AreEqual(
const T& expected,
const T& actual,
const wchar_t* message = NULL,
const __LineInfo* pLineInfo = NULL)
If we are trying to stay in un-managed C++, and we don't care what the error message looks like, this is probably a better option than the accepted answer:
Assert::IsTrue(s1==s2)
By better, I mean it is at least easy to read.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With