Unnecessary unit-test mocking?

A few months ago, I worked on an existing project. I always like when a project have unit tests because it helps me understand how the functions are being used and I can use it as a playground to experiment with the functions. However, when I dived into the project, many things are mocked unnecessarily. For example, there is a function to compute a checksum that can be executed on the unit tests, and yet it was mocked.

uint8_t compute_8bit_checksum(uint8_t *data, uint16_t length); // On the unit tests, this is mocked with the expected input and expected return. 

I also saw a wrapper for memset to clear an array

void clearArray(uint8_t * arr, uint16_t length); // this is mocked as well 

On my previous projects, I use mocks only if necessary and mostly on things that are external and out of my control (especially those that relies on external devices, external database, clock/timers, functions that relies on random number generators, computation intensive functions). But I don't mock those that can be run on unit tests with deterministic return values (like those above). I believe the two things shown above could be unit tested directly and no need to mock them. And the unit test is challenging to read because of lots of mocking.

The previous dev resigned so I don't know the reasons for this. I am not sure if i am missing anything or what are the rationale of mocking something that can be executed on the unit tests with a deterministic return value? I was under the impression that the previous dev learned mocking and he/she became too enthusiastic about mocking and possibly became too adventurous and led to its uncontrolled usage. Anyone who had experienced the same?

submitted by /u/engineerFWSWHW
[link] [comments]

from Software Development – methodologies, techniques, and tools. Covering Agile, RUP, Waterfall + more! https://ift.tt/BwNOu3L

Leave a comment

Design a site like this with WordPress.com
Get started
search previous next tag category expand menu location phone mail time cart zoom edit close