How I finally started mocking in tests

Topic: Mocking in Test Classes
Target Group: Developer and Architects
Complexity: Advanced

Every Developer has heard of mocking in tests and why you should do it. Some amazing developers even do it.

I’ve seen the adverse effect of missing mocks in Test Classes. Writing Test Classes without mocks is a chore and therefore done poorly (by me).

In the case I manage to write proper tests, running all of them takes ages. The more spaghetti the code becomes, the worse it gets.

I’ve been trying to get into mocking in my tests for years. Unfortunately, the mocking frameworks I knew (fflib…) are way to complex for me.

This is over now! Again, Matthew Gerry came to the rescue. 

He explains the concept of mocks, live codes, and shares two super simple, lightweight libraries, one for mock sObjects and a mocking framework.

It took me just a few hours and my first mocked Unit test was implemented.

So far I’ve mocked 3 of my test classes. One test went from a monster with 50 lines of Test Setup and about a minute of execution to minimal Test Setup and seconds of execution. Magic!

Implementing the mocks forced me to implement a basic SOC (QueryService, DmlService) AMAZING!

I know, I’m just at the beginning of my mocking journey, but I already can see where it leads me.

Thanks to Suraj Pillai ☁ , John Ellison , James Simone Simone for UniversalMocker

PS: Architects, Ask your developer about mocking today.