Skip to content

Commit

Permalink
Refactor Test Fixture to support different worlds (#160)
Browse files Browse the repository at this point in the history
Currently, the `LrauvTestFixture` allows us to only load `BuoyantTethys.sdf`. This PR refactors the test fixture. It creates two test classes:
* `LrauvTestFixtureBase` - An abstract base class which contains all the common functionality.
* `LrauvTestFixture` - Inherits from `LrauvTestFixtureBase` and loads the `buoyant_tethys.sdf`.

Signed-off-by: Arjo Chakravarty <arjo@openrobotics.org>
  • Loading branch information
arjo129 authored Mar 2, 2022
1 parent e1749b5 commit e48b561
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions lrauv_ignition_plugins/test/helper/LrauvTestFixture.hh
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@ double angleDiff(double _a, double _b)
return diff.Radian();
}

/// \brief Convenient fixture that provides boilerplate code common to most
/// LRAUV tests.
class LrauvTestFixture : public ::testing::Test
/// \brief Abstract base class for fixture that provides boilerplate code common
/// to most LRAUV tests.
class LrauvTestFixtureBase : public ::testing::Test
{
// Documentation inherited
protected: void SetUp() override
/// Setup the specified world.
/// \param[in] _worldName Name of the world to load.
public: void SetUp(const std::string &_worldName)
{
ignition::common::Console::SetVerbosity(4);

Expand All @@ -66,12 +67,12 @@ class LrauvTestFixture : public ::testing::Test
commandTopic);

auto stateTopic = "/tethys/state_topic";
this->node.Subscribe(stateTopic, &LrauvTestFixture::OnState, this);
this->node.Subscribe(stateTopic, &LrauvTestFixtureBase::OnState, this);

// Setup fixture
this->fixture = std::make_unique<ignition::gazebo::TestFixture>(
ignition::common::joinPaths(
std::string(PROJECT_SOURCE_PATH), "worlds", "buoyant_tethys.sdf"));
std::string(PROJECT_SOURCE_PATH), "worlds", _worldName));

fixture->OnPostUpdate(
[&](const ignition::gazebo::UpdateInfo &_info,
Expand Down Expand Up @@ -302,4 +303,15 @@ class LrauvTestFixture : public ::testing::Test
/// \brief Publishes commands
public: ignition::transport::Node::Publisher commandPub;
};


/// \brief Loads the default "buyant_tethys.sdf" world.
class LrauvTestFixture : public LrauvTestFixtureBase
{
// Documentation inherited
protected: void SetUp() override
{
LrauvTestFixtureBase::SetUp("buoyant_tethys.sdf");
}
};
#endif

0 comments on commit e48b561

Please sign in to comment.