Gazebo Gazebo

API Reference

3.15.1
TestFixture Class Reference

Helper class to write automated tests. It provides a convenient API to load a world file, step simulation and check entities and components. More...

#include <TestFixture.hh>

Public Member Functions

 TestFixture (const ServerConfig &_config)
 Constructor. More...
 
 TestFixture (const std::string &_path)
 Constructor. More...
 
virtual ~TestFixture ()
 Destructor. More...
 
TestFixtureFinalize ()
 Finalize all the functions and add fixture to server. Finalize must be called before running the server, otherwise none of the On* functions will be called. The OnConfigure callback is called immediately on finalize. More...
 
TestFixtureOnConfigure (std::function< void(const Entity &_entity, const std::shared_ptr< const sdf::Element > &_sdf, EntityComponentManager &_ecm, EventManager &_eventMgr)> _cb)
 Wrapper around a system's pre-update callback. More...
 
TestFixtureOnPostUpdate (std::function< void(const UpdateInfo &, const EntityComponentManager &)> _cb)
 Wrapper around a system's post-update callback. More...
 
TestFixtureOnPreUpdate (std::function< void(const UpdateInfo &, EntityComponentManager &)> _cb)
 Wrapper around a system's pre-update callback. More...
 
TestFixtureOnUpdate (std::function< void(const UpdateInfo &, EntityComponentManager &)> _cb)
 Wrapper around a system's update callback. More...
 
std::shared_ptr< gz::sim::ServerServer () const
 Get pointer to underlying server. More...
 

Detailed Description

Helper class to write automated tests. It provides a convenient API to load a world file, step simulation and check entities and components.

Usage

// Load a world with a fixture gz::sim::TestFixture fixture("path_to.sdf");

// Register callbacks, for example: fixture.OnPostUpdate([&](const gz::sim::UpdateInfo &, const gz::sim::EntityComponentManager &_ecm) { // Add expectations here }).Finalize(); // Be sure to call finalize before running the server.

// Run the server fixture.Server()->Run(true, 1000, false);

Constructor & Destructor Documentation

◆ TestFixture() [1/2]

TestFixture ( const std::string _path)
explicit

Constructor.

Parameters
[in]_pathPath to SDF file.

◆ TestFixture() [2/2]

TestFixture ( const ServerConfig _config)
explicit

Constructor.

Parameters
[in]_configServer config file

◆ ~TestFixture()

virtual ~TestFixture ( )
virtual

Destructor.

Member Function Documentation

◆ Finalize()

TestFixture& Finalize ( )

Finalize all the functions and add fixture to server. Finalize must be called before running the server, otherwise none of the On* functions will be called. The OnConfigure callback is called immediately on finalize.

◆ OnConfigure()

TestFixture& OnConfigure ( std::function< void(const Entity &_entity, const std::shared_ptr< const sdf::Element > &_sdf, EntityComponentManager &_ecm, EventManager &_eventMgr)>  _cb)

Wrapper around a system's pre-update callback.

Parameters
[in]_cbFunction to be called every pre-update The _entity and _sdf will correspond to the world entity.
Returns
Reference to self.

◆ OnPostUpdate()

TestFixture& OnPostUpdate ( std::function< void(const UpdateInfo &, const EntityComponentManager &)>  _cb)

Wrapper around a system's post-update callback.

Parameters
[in]_cbFunction to be called every post-update
Returns
Reference to self.

◆ OnPreUpdate()

TestFixture& OnPreUpdate ( std::function< void(const UpdateInfo &, EntityComponentManager &)>  _cb)

Wrapper around a system's pre-update callback.

Parameters
[in]_cbFunction to be called every pre-update
Returns
Reference to self.

◆ OnUpdate()

TestFixture& OnUpdate ( std::function< void(const UpdateInfo &, EntityComponentManager &)>  _cb)

Wrapper around a system's update callback.

Parameters
[in]_cbFunction to be called every update
Returns
Reference to self.

◆ Server()

Get pointer to underlying server.


The documentation for this class was generated from the following file: