utra-robosoccer / soccer-embedded

Collection of embedded programs for an autonomous humanoid soccer robot
http://utrahumanoid.ca
32 stars 8 forks source link

Unit tests using gmock objects should use one object instantiation per unit test #174

Closed rfairley closed 5 years ago

rfairley commented 5 years ago

Describe the bug Unit tests using mocks should use a separate mock object instance per test. Right now some of our tests use global mock instances, which can possibly become corrupt as state gets transferred between tests. This can cause reporting of wrong reasons for test failure.

See #150 for a description of the behavior and reproducible results.

In googlemock examples, the Mock* object is declared within the TEST() block: https://github.com/google/googletest/blob/master/googlemock/docs/ForDummies.md#using-mocks-in-tests

Additional context

Fixing this requires going through the unit test files in Common/test and either declaring the mock in a test fixture, or declaring one instance of the mock object per test (the former is cleaner and preferred, see an example).