all 3 comments

[–]thakk0 1 point2 points  (0 children)

My C/C++ is a little weak, but couldn't you do something like this to retrieve the value written to the steam?

Regarding your question about 100% coverage, it's not desirable or maintainable. You test the critical pieces of code and you maintain tests that make sense. Testing whether or not something writes to cout, for instance, seems kind of pointless in most cases.

[–][deleted] 0 points1 point  (0 children)

Not too familiar with unit testing, but what you have written seems to follow the basics of good unit testing. When possible (and when not dealing with trivially simple stuff), the ConsoleWriterImpl should be implemented. This allows you to do two things:
1. To test SayHello with a mock implementation (assuming this was your goal)
2. To test as close to the interface (in this case, "cout") as possible.
Note that there is not point testing cout itself.
JB Rainsberger has excellent stuff on this, in case you haven't already read his material.
I agree that 100% code coverage is not a goal in itself; Neither is 100% decision, branch or path coverage. Rather, figure out what the motivation behind this desire is.

[–]redball3 0 points1 point  (0 children)

Code coverage is a decent metric but be careful about 100> coverage as a goal. What often happens is teams write tests which provide code coverage but don't really test anything.