Teaching Mockito in a Less Mystical Way
It was my first time teaching Mockito to a face-to-face class yesterday (I've taught it before to online classes), so it was the first time seeing the expression on their faces. Their eyes turned glassy, so I knew they were lost.
"Are you guys wondering where the heck these objects came from?" I asked.
"Yep."
"Too much magic, eh? Expecto patronum!"
I gave a long-winded explanation of what was basically the Proxy pattern. After I struggled to explain it in a few different ways, they got it and we moved on.
I realize that perhaps I should have started with how we created mocks before we had mocking frameworks. I could have had the IDE generate an implementation of one of the Repositories we were mocking, with stubbed methods, and used that in the test. Probably taking 15 minutes to show how it was done in an "old school" way (~20 years ago?) will allow the trainees to understand what Mockito was doing under the hood.
These trainees (devs of a multinational bank) have been learning an overwhelming amount of "magic" these past few weeks - Spring, JPA... today I'm actually going to cover TestContainers. As a trainer, I need to find ways to demystify the magic.