TRUNK-3586 Update unit testing environment to use mocks

(cherry picked from commit 586ec2453942f474ef1d3ea625bfa0876ed4e1fd)
TRUNK-3586 Slightly improved and prepared for backporting

(cherry picked from commit bd5a8b0f294672f3fdf348270d41252c444d3d05)