Unit testing company Typemock Ltd. points to new research into Agile software application development practices calling for a deeper level of granularity into extended code analysis in the pursuit of better debugging. The company highlights findings which estimate that 70% of Agile developers say that they unit test, but says that much less of them really write automated, isolated unit tests.
Since isolation requires "mocking", developers are not testing their software as thoroughly as they might, says Typemock product manager Gil Zilberfeld, who asserts that mocking paves the way to:
- Running tests faster
- Debugging tests faster
- Writing tests faster
- Covering edge cases
"When your unit tests use mocks, they run faster. Instead of expensive calls to the database or the cloud, you can shorten tests to milliseconds. A full test suite can run in seconds instead of hours, giving you immediate feedback on your code," says Zilberfeld.
Typemock says that by using its methodologies and technologies when a unit test fails, you don't need to start up the entire application, set a breakpoint, miss it, return to it, shut it down, fix it, and repeat until it's really fixed — as unit tests (typically) test very small pieces of code, where the rest is mocked.
"Suppose you had a thousand tests, each requiring a special database setup — and you'll need to clean up after every scenario. How much time would you spend on just these steps? Setting up mocks is way easier and much more effective. Finally, what about those edge cases, where you actually need to shut down the Internet? Instead of cutting real power cords, use a mock instead. Tests give reliable results, plus, the rest of us can keep using Wikipedia," says Zilberfeld.
So if we accept the assertion that mocking is really what makes unit tests work, our code should and could be easier to maintain as a result.