Boost logo

Boost Users :

Subject: Re: [Boost-users] Boost.Mock ?
From: Mathieu Champlon (m.champlon_at_[hidden])
Date: 2014-01-14 00:52:05


Hi Gennadiy,

On 13/01/2014 04:25, Gennadiy Rozental wrote:
> Hi Mathieu,
>
> Can you please summary here in few paragraphs:
>
> * What exactly you want to test?

It's probably up to the user to decide what needs to be tested.
Any piece of code (sub-system) which interacts with another (the rest of
the system) can be tested, with a few restrictions. For instance the
library won't be able to inject a different function implementation
without some kind of hook (e.g. a function pointer passed to the code
under test).

> * What exactly you want to mock?

Classes, concepts, functions and function objects are supported, see
http://mat007.users.sourceforge.net/boost_mock/boost_mock/reference.html#boost_mock.reference.creation

> * How do you want to record your expectations?
> * How do you want to test against these expectations?
> * Can you show some concise example if using this library? What do I start
> with? How do I write a test case?
>

Does the motivation example from the introduction answer your questions ?
http://mat007.users.sourceforge.net/boost_mock/boost_mock/motivation.html

I'll copy it here if you want to discuss it:

class view
{
public:
     virtual void display( int result ) = 0;
};

class calculator
{
public:
     calculator( view& v );

     void add( int a, int b ); // the result will be sent to the view 'v'
};

BOOST_MOCK_BASE_CLASS( mock_view, view ) // declare a 'mock_view' class implementing 'view'
{
     BOOST_MOCK_METHOD( display, 1 ) // implement the 'display' method from 'view' (taking 1 argument)
};

BOOST_AUTO_TEST_CASE( zero_plus_zero_is_zero )
{
     mock_view v;
     calculator c( v );
     BOOST_MOCK_EXPECT( v.display ).once().with( 0 ); // expect the 'display' method to be called once (and only once) with a parameter value equal to 0
     c.add( 0, 0 );
}

Cheers,
MAT.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net