<<../components/_v2_banner.md>>
Integration testing scenarios involve two or more components operating in the same realm and exchanging capabilities. While the majority of tests are unit tests that span only a single component, integration testing scenarios call for defining realm topologies and capability routes.
We demonstrate the driver pattern for writing an integration test with a custom component topology.
We define the BUILD.gn
file as shown below:
{% includecode gerrit_repo="fuchsia/fuchsia" gerrit_path="examples/components/basic/integration_tests/BUILD.gn" region_tag="example_snippet" adjust_indentation="auto" %}
The topology for the test realm in this example looks as follows:
In this example the test package hello-world-integration-test
contains four components:
hello-world-integration-test-component
has two children:
This is a simple component realm which launches hello-world-integration-test-driver
and offers it the helper services.
Finally, note that all components under test are included in the test‘s own package. This promotes hermeticity and has many benefits. For instance it’s possible to push an updated version of the same package to the device and run the test again without worrying whether the different components are all of the same version or have fallen out of sync.
Note that the driver component exposes fuchsia.test.Suite
from its child to the test root. The root of a test realm must always expose this protocol in order to integrate with the Test Runner Framework.
The root realm is defined as follows:
{% includecode gerrit_repo="fuchsia/fuchsia" gerrit_path="examples/components/basic/integration_tests/meta/hello-world-integration-test.cml" region_tag="example_snippet" adjust_indentation="auto" %}
hello-world-integration-test-driver
contains the test logic and expectations. The driver launches the hello-world
component and asserts that it is writing the expected strings to the log.
Note that this is a Rust test, and therefore includes rust/default.shard.cml
as required to integrate with the Test Runner Framework.
{% includecode gerrit_repo="fuchsia/fuchsia" gerrit_path="examples/components/basic/integration_tests/meta/hello-world-integration-test-driver.cml" region_tag="example_snippet" adjust_indentation="auto" %}
The code for this example can be found under //examples/components/basic/integration_tests
.