OpenAssetIO [beta]
An abstract API for generalising interactions between a host application and an asset management system
Testing Your Implementation

Testing Manager Plugins

The API distribution includes a test harness that can be used to test the implementation of any given Manager Plugin. It is a unittest based framework that can be used stand-alone via the command line, or extended with additional test suites for extra coverage.

The harness acts as an OpenAssetIO host. Two things are needed to test any given codebase:

  • A PythonPluginSystemManagerPlugin implementation for the manager to be tested.
  • A Python 'fixtures' file that provides valid inputs, and expected outputs for that manager.

The Fixtures File

OpenAssetIO only defines a set of methods that a host can use to communicate with a manager. It does not dictate the specifics of what constitutes valid inputs, or output from any given manager. This is specific to its data model and implementation.

Consequently the test harness needs to be supplied with valid values to pass to methods such as isEntityReferenceString, and the expected values from methods such as identifier

The file should set a top level variable called fixtures, holding a dict structured as-per the fixtures parameter documented here. For example:

1 identifier = <your plugin identifier>
2 
3 fixtures = {
4  "identifier": identifier,
5  "Test_identifier": {
6  "test_matches_fixture": {
7  "identifier": identifier
8  }
9  },
10  "Test_displayName": { ... },
11  ...
12 }
Note
A comprehensive example fixtures file is provided as part of the manager template project (see fixtures.py).

Using the Command Line

The simplest way to test a Manager Plugin is via the command line:

1 python -m openassetio.test.manager -f <path to fixtures file>

If desired, additional arguments can be passed to the unittest framework as if the module was being used directly. The following, for example, enables verbose mode:

1 python -m openassetio.test.manager -f <path to fixtures file> -v

The CLI will run the standard API compliance suite. This checks that the plugin's implementation returns the expected types and handles invalid input appropriately.

Scripting The Test Harness

To run additional test suites, to validate manager-specific business logic, the CLI entry point can be trivially recreated in python by calling the harness API directly:

1 from openassetio.test.manager import harness, apiComplianceSuite
2 import custom_suite
3 
4 # Load the fixtures file
5 fixtures = harness.fixturesFromPyFile(path_to_fixtures_file)
6 
7 # Run the standard suite
8 harness.executeSuite(apiComplianceSuite, fixtures)
9 
10 # Run a custom suite. This could load fixtures from an alternate
11 # file, or generated by other means if desired.
12 harness.executeSuite(custom_suite, fixtures)
Note
The API compliance suite may serve as a useful reference when authoring custom test suites.
See also
harness
apiComplianceSuite