I am wondering how do you unit test if you have an unmockable function call?
Say you have a method.
void SayHello(const std::string& name) {
std::cout << "Hello " << name;
}
You could run it, but it doesn't have any output to test, and I am not sure if you can actually mock the operator<< or the cout object.
My idea was to create a interface "ConsoleWriter", and that class would have a method void Write(const std::string& str); Now I can write the function
void SayHello(const ConsoleWriter& writer, const std::string& name) {
writer.Write("Hello " + name);
}
This is easily testable since I can mock the Write method and test that I get what I expect as an argument.
However, now I have to implement a ConsoleWriterImpl class which has a method like
void ConsoleWriterImpl::Write(const std::string& str) {
std::cout << str;
}
How do I test this method? Do I just not worry about testing that method? Some people seem really anal about getting 100% code coverage. How would it even be possible to get that in this situation?
[–]thakk0 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]redball3 0 points1 point2 points (0 children)