[Merge] lp:~mardy/location-service/lp1499256 into lp:location-service

Thomas Voß thomas.voss at canonical.com
Thu Oct 15 08:23:00 UTC 2015


> On 10/14/2015 02:45 PM, Thomas Voß wrote:
> > A singleton is fine here, I would however prefer: static MockHardwareGps
> *instance() { static MockHardwareGps inst; return &inst; }
> > With that, you can get rid of custom ctor and dtor, as well as the static
> instance_.
> 
> I tried that, but it doesn't work because the object is instantiated in
> the test as
> 
>    NiceMock<MockHardwareGps> hardwareGps;
> 
> and not via the MockHardwareGps::instance() method; therefore, two
> objects are created.
> A possibility would be to make the instance() method return a NiceMock'd
> instance. Would you prefer that?

Nah, stick with the instance member. Returning a NiceMock would require individual tests to manually verify and clear expectations as one global object would be reused for all tests. I think the benefit of your code is a fresh instance per test.

Some documentation would be great, though :)

-- 
https://code.launchpad.net/~mardy/location-service/lp1499256/+merge/274381
Your team Ubuntu Phablet Team is subscribed to branch lp:location-service.



More information about the Ubuntu-reviews mailing list