mirror of
https://github.com/mat007/turtle.git
synced 2026-06-22 12:13:43 +00:00
git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@753 860be788-9bd5-4423-9f1e-828f051e677b
41 lines
1 KiB
Text
41 lines
1 KiB
Text
[/
|
|
/ Copyright (c) 2014 Mathieu Champlon
|
|
/
|
|
/ Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
/ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
/]
|
|
|
|
[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]
|