turtle/build/boost/doc/motivation.qbk
2012-11-28 23:01:45 +00:00

34 lines
857 B
Text

[section Motivation]
[import example/motivation.cpp]
[import example/calculator.hpp]
[import example/mock_view.hpp]
[import example/view.hpp]
Consider a (very) simple calculator class :
[simple_calculator]
Obviously writing unit tests for such a class is trivial, one of them could be :
[simple_zero_plus_zero_is_zero]
What now if the calculator class looks more like this :
[view]
[calculator]
Writing unit tests becomes a bit more tedious and requires some boiler-plate code, for instance :
[my_view]
[zero_plus_zero_is_zero_without_mock_object]
Mock objects main purpose is to alleviate the user from the burden of writing all this boiler-plate code.
Here is how the last test can be rewritten using a mock object :
[mock_view]
[zero_plus_zero_is_zero_with_mock_object]
and all the checks are automatically handled by the library.
[endsect]