Attending this event?
View analytic
Wednesday, September 26 • 15:15 - 15:45
To Kill a Mocking Framework: Tools and Techniques for Testing Callbacks Using Standard C++

Sign up or log in to save this to your schedule and see who's attending!

Callbacks are a commonly used technique for delivering data and passing control from one component to another. Their many uses include handling asynchronous events, providing customizations, and (with polymorphic lambdas) enable functional-style programming in C++. Testing components which invoke polymorphic callbacks can be a challenge, and this leads some developers to either avoid testing altogether, or to rely on mocking frameworks such as Google Mock.

Mocking frameworks sometimes rely on a Domain Specific Language or other syntax for expressing expectations on the mocked objects. My intention for this talk is to outline some ways in which standard C++ features and idioms can be used to test components with callbacks, as an alternative to such frameworks. In particular, I'll show how employing core features - lambdas, std::function, and RAII - allows us to build mocks which clearly express the desired behavior from the code under test, whilst being expressive and hard to misuse.

avatar for Alastair Rankine

Alastair Rankine

VP, Automated Market Making, Morgan Stanley

Wednesday September 26, 2018 15:15 - 15:45

Attendees (32)