Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using mocking during testing does it worth the effort?

During this semester my professor tried to convince us why is good to use unit tests during development, why is it good to validate data(Microsoft Application Block) and also he told us about using mocking(RhinoMocks) in order to test our methods when we didn't had access to a database.

I had to do some unit tests with mocking and in order to make them work i had to create by hand the objects hierarchy that was needed in order to test my method(It took me a while to write everything i needed).

The question that i want to put: in production is it useful to use mocking? Should i use it every time i have the chance? And also the effort made to write everything in order to test a method with mocks does it pay off?

thank you

like image 547
Sorin Antohi Avatar asked Nov 05 '22 16:11

Sorin Antohi


1 Answers

Yes, using mock objects as one among your many unit testing tools is definitely a worthwhile endeavour.

However, it goes best with Test-Driven Development because the tests drive the design. When you begin to feel the pain of tightly coupled code because you have to maintain deeply nested structures, you know it's time to refactor to a more loosely coupled API.

like image 71
Mark Seemann Avatar answered Nov 15 '22 12:11

Mark Seemann