SJSURoboticsTeam / urc-central-2021

Track progress and information for the URC 2021 competition
MIT License
1 stars 0 forks source link

Create Spy for Wheel class #201

Closed naterpotatoers closed 2 years ago

naterpotatoers commented 2 years ago

Been writing unit tests for drive system and I believe the HomeWheel() function is causing problems when testing rover_drive_system. Ideally I want to spy on Wheel class and just return the HomeWheel() function. However that isn't working properly as I can't spy on the GetSteerAngle() as shown below.

  SECTION("Spying on Wheel")
  {
    Mock<drive::Wheel> spy(wheel);
    When(Method(spy, GetSteerAngle)).AlwaysReturn(10);
    drive::Wheel & test = spy.get();
    CHECK(test.GetSteerAngle() == 10);
  }

Results in the following: ERROR: CHECK( test.GetSteerAngle() == 10 ) is NOT correct! values: CHECK( 0 == 10 ) I must be doing something wrong...

naterpotatoers commented 2 years ago

The solution was making the function virtual. In order to spy on a function it needs to be virtual.