C++Now 2017 has ended
Back To Schedule
Wednesday, May 17 • 11:00am - 12:30pm
Mocking C++ (full-length version)

Log in to save this to your schedule, view media, leave feedback and see who's attending!

Feedback form is now closed.
Slides: https://github.com/boostcon/cppnow_presentations_2017/blob/master/05-17-2017_wednesday/mocking_cpp_full_length_version__peter_bindels__cppnow_05-17-2017.pdf
Video: https://www.youtube.com/watch?v=t0wLm2iiEH0

When unit testing, many times you'll be re-testing already tested components, unnecessarily slowing down your code or pulling in dependencies and unreliabilities you'd like to avoid. There's a way to avoid that - use a mock component that pretends to do what you ask it to, but that instead just gives you the answers your test needs. It's a much easier way to get your tests for corner cases and bad return values written, and it makes them more reliable to boot.

The downside is that to implement it properly, you would need to have reflection. Java and C#, both with great mocking libraries use reflection to create their mock objects, and many times it's been posed that C++ just cannot do it without many macros, manual labor, unreliable scripts or duplicated code, because it lacks the ability. We show otherwise - unlike some C++ mocking libraries would have you believe, you can actually make mock objects without repeating - or implementing for the first time! - the classes you're testing with.

avatar for Peter Bindels

Peter Bindels

Expert Software Engineer, TomTom NV
Original/first author of HippoMocks (github.com/dascandy/hippomocks), first author of cpp-dependencies (github.com/tomtom-international/cpp-dependencies), long-standing moderator at forum.osdev.org. Convinced of the ability of people to make things more complicated than they actually... Read More →

Wednesday May 17, 2017 11:00am - 12:30pm MDT