If you or your team owns non-hermetic tests or tests which require custom runners, you need to create a test realm to execute those tests.
Below you can see a sample test realm
{% includecode gerrit_repo="fuchsia/fuchsia" gerrit_path="src/sys/testing/meta/test_realm.cml" %}
The test realm manifest must include specific sections to facilitate the execution of test components by the Test Manager.
Every test realm must have one or more test collections where the Test Manager
can execute tests. In the provided sample test realm, we utilize test collections using shards. You can refer to the System tests collection as an example, which can run various non-hermetic tests.
Each test realm must expose protocol fuchsia.component.Realm
. This protocol provides Test Manager the capability to launch components inside the realm.
Each test realm must include the realm builder shard which helps the Test Manager to execute tests dynamically inside the collection.
While optional, it is recommended for most test realms to include standard test runners for executing basic tests within the realm. In cases where custom test runners are needed, they can be included and added to the environment of the test collection.
Register your moniker in our build rules:
_type_moniker_map = { system = "/core/testing:system-tests" test_arch = "/core/testing:test-arch-tests" ... <new_type> = "/path/to/test/realm/moniker" }
Assign the new test_type
to your test:
// BUILD.gn fuchsia_test_component("my_test") { component_name = "my_test" manifest = "meta/my_test.cml" deps = [ ":my_test_bin" ] test_type = "<new_type>" }
Now you can run test can be executed using fx test
.
Integrate your testing scripts to call ffx test
with the realm moniker:
ffx test run --realm "/path/to/test/realm/moniker" <test_url>