创建一个单一的 XML 配置来定义测试并不总是可行的。如果您想重新使用部分设置来运行类似的测试,您将被迫复制和维护两个巨大的 XML 文件。
这就是 Tradefed XML 配置定义中的template
和include
标签派上用场的地方。它们允许您在某些 XML 配置中设置占位符以添加另一个 XML 配置的一部分。
模板的示例定义
<configuration description="Common base configuration for local runs with minimum overhead">
<build_provider class="com.android.tradefed.build.BootstrapBuildProvider" />
<template-include name="preparers" default="empty" />
<template-include name="test" default="empty" />
<template-include name="reporters" default="empty" />
</configuration>
模板是具有引用它们的name
和可选default
字段的占位符。默认字段定义应使用的默认替换 XML。
为了替换给定配置的模板,需要将以下命令参数添加到命令行:
--template:map <name of template>=<replacement XML config path>
--template:map preparers=empty
例如:
<template-include name="preparers" default="empty" />
本例中的empty
引用是指空的empty.xml
配置不包含任何内容;我们用它作为我们的参考来替换 nothing 。
XML 配置的路径可以是绝对或相对于 Tradefed 的 JAR 资源中的res/config
文件夹。以下是他们的一些位置:
- 工具/tradefederation/core/res/config
- 工具/tradefederation/core/tests/res/config
- 工具/tradedeferation/contrib/res/config
包含的示例定义
<configuration description="Common base configuration for local runs with minimum overhead">
<build_provider class="com.android.tradefed.build.BootstrapBuildProvider" />
<include name="empty"/>
</configuration>
包含比模板更简单,因为它们不需要命令行参数;他们直接在name
标签中扩展引用的 XML。与模板类似,配置的路径可以是绝对的或相对的。不过,对于includes
,我们建议仅使用相对路径,因为它们在 Tradefed 中更便携。如果将 Tradefed 移至另一台机器,绝对路径将无效。
配置错误
在配置错误的情况下,例如找不到替换 XML 时,Tradefed 将抛出ConfigurationException
并描述似乎缺少或配置错误的内容。