编辑测试运行配置 XML 文件
更新:2007 年 11 月
如如何:编辑测试运行配置文件中所述,可以采用两种方法来更改测试运行配置:使用测试运行配置编辑器,或编辑测试运行配置文件的 XML。通常,首先尝试使用测试运行配置编辑器来进行更改。如果该方法无法更改要更改的特定配置设置,请编辑测试运行配置文件。
为了帮助您确定要使用哪种方法,本主题说明了测试运行配置文件的一般结构,并提供两个可以手动编辑但不能使用测试运行配置编辑器进行编辑的设置示例。
使用测试运行配置编辑器来更改测试运行配置设置时,可以看到反映在此文件中的那些更改。更改此文件中的值时,可以看到反映在测试运行配置编辑器中的部分(但并非全部)更改。
有关如何使用测试运行配置编辑器的更多信息,请参见如何:指定测试运行配置。
示例测试运行配置文件
在下面的示例文件中,某些元素以粗体文本显示。这些元素对应于使用测试运行配置编辑器可以进行的设置的常规区域。
<?xml version="1.0" encoding="utf-8"?>
<Tests>
<TestRunConfiguration type="Microsoft.VisualStudio.TestTools.Common.TestRunConfiguration">
<id type="Microsoft.VisualStudio.TestTools.Common.TestRunConfigurationId">
<id type="System.Guid">5d9344ed-bbde-4850-b05e-a7058096e956</id>
</id>
<name type="System.String">TestRunConfig1</name>
<description type="System.String">This is a default test run configuration for a local test run.</description>
<isCodeCoverageEnabled type="System.Boolean">True</isCodeCoverageEnabled>
<codeCoverageItems type="System.Collections.Generic.List`1[[Microsoft.VisualStudio.TestTools.Common.CodeCoverageItem, Microsoft.VisualStudio.QualityTools.Common, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]]">
<_items type="Microsoft.VisualStudio.TestTools.Common.CodeCoverageItem[]">
<element type="Microsoft.VisualStudio.TestTools.Common.CodeCoverageItem">
<binaryFile type="System.String">bin\Debug\ClassLibrary1.dll</binaryFile>
<keyFile type="System.String">Library1.snk</keyFile>
<pdbFile type="System.String">bin\Debug\ClassLibrary1.pdb</pdbFile>
<instrumentInPlace type="System.Boolean">True</instrumentInPlace>
<outputDirectory type="System.String" />
</element>
</_items><_size type="System.Int32">1</_size>
<_version type="System.Int32">1</_version>
</codeCoverageItems>
<codeCoverageKeyFile type="System.String" />
<aspNetProjectCoverageItems type="System.Collections.Generic.List`1[
[Microsoft.VisualStudio.TestTools.Common.AspNetProjectItem, Microsoft.VisualStudio.QualityTools.Common, Version=8.0.0.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]]">
<_size type="System.Int32">0</_size>
<_version type="System.Int32">0</_version>
</aspNetProjectCoverageItems>
<isExecutedRemotely type="System.Boolean">False</isExecutedRemotely>
<bucketSize type="System.Int32">200</bucketSize>
<bucketThreshold type="System.Int32">1000</bucketThreshold>
<runTimeout type="System.Int32">0</runTimeout>
<testTimeout type="System.Int32">300000</testTimeout>
<agentNotRespondingTimeout type="System.Int32">300000</agentNotRespondingTimeout>
<deploymentTimeout type="System.Int32">300000</deploymentTimeout>
<controllerName type="System.String" />
<plugins type="System.Collections.Generic.List`1[[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]">
<_size type="System.Int32">0</_size>
<_version type="System.Int32">0</_version>
</plugins>
<testTypeSpecificData type="System.Collections.Generic.Dictionary`2[[Microsoft.VisualStudio.TestTools.Common.TestType, Microsoft.VisualStudio.QualityTools.Common, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a],[Microsoft.VisualStudio.TestTools.Common.ITestTypeSpecificRunConfigurationData, Microsoft.VisualStudio.QualityTools.Common, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]]">
<buckets type="System.Int32">-1,-1,0</buckets>
<entries type="System.Collections.Generic.Dictionary`2+Entry[[Microsoft.VisualStudio.TestTools.Common.TestType, Microsoft.VisualStudio.QualityTools.Common, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a],[Microsoft.VisualStudio.TestTools.Common.ITestTypeSpecificRunConfigurationData, Microsoft.VisualStudio.QualityTools.Common, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]][]">
<element type="Microsoft.VisualStudio.TestTools.WebTesting.WebTestRequestHeader, Microsoft.VisualStudio.QualityTools.WebTestFramework, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<m_name type="System.String">User-Agent</m_name>
<m_value type="System.String">Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)</m_value>
</element>
</entries>
<count type="System.Int32">1</count>
<version type="System.Int32">1</version>
<freeList type="System.Int32">-1</freeList>
<freeCount type="System.Int32">0</freeCount>
<comparer type="System.Collections.Generic.ObjectEqualityComparer`1[[Microsoft.VisualStudio.TestTools.Common.TestType, Microsoft.VisualStudio.QualityTools.Common, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]]" />
</testTypeSpecificData>
<userDeploymentRoot type="System.String" />
<useDefaultDeploymentRoot type="System.Boolean">True</useDefaultDeploymentRoot>
<deploymentItems type="Microsoft.VisualStudio.TestTools.Common.DeploymentItemCollection" />
<testRunNamingScheme type="Microsoft.VisualStudio.TestTools.Common.TestRunNamingScheme">
<appendTimeStamp type="System.Boolean">True</appendTimeStamp>
<useDefault type="System.Boolean">True</useDefault>
</testRunNamingScheme>
<setupCommand type="System.String" />
<cleanupCommand type="System.String" />
<abortRunOnError type="System.Boolean">False</abortRunOnError>
<mapIPAddresses type="System.Boolean">False</mapIPAddresses>
<agentProperties type="System.Collections.Specialized.StringDictionary, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<hostData type="Microsoft.VisualStudio.TestTools.Common.HostRunConfigurationData">
<mapHostSpecificData type="System.Collections.Generic.Dictionary`2[[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],
[Microsoft.VisualStudio.TestTools.Common.IHostSpecificRunConfigurationData, Microsoft.VisualStudio.QualityTools.Common, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]]">
<count type="System.Int32">0</count>
<version type="System.Int32">0</version>
<freeList type="System.Int32">0</freeList>
<freeCount type="System.Int32">0</freeCount>
<comparer type="System.Collections.Generic.GenericEqualityComparer`1[[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]" />
</mapHostSpecificData>
</hostData>
<ignoredDependentAssemblies type="System.String" />
<apartmentState type="System.Threading.ApartmentState">
<value__ type="System.Int32">0</value__>
</apartmentState>
</TestRunConfiguration>
</Tests>
示例
以下部分说明如何在控制测试运行配置的 XML 文件中进行特定更改。由于无法使用测试运行配置编辑器进行这些更改,因此必须在 XML 中进行更改。
更改测试结果的默认位置
更改检测位置并指定其他密钥文件
更改测试结果的默认位置
运行测试时,这些测试的结果将自动保存到磁盘默认位置。如果您不更改测试运行配置 XML 文件,则布尔变量 useDefaultDeploymentRoot 将保留其默认值 True。在这种情况下,测试结果将保存到下列位置:
在 Visual Studio IDE 中运行的测试的结果保存到当前解决方案文件夹下的 TestResults 文件夹中。
使用命令行命令 MSTest.exe 运行的测试的结果保存在当前文件夹下的 TestResults 文件夹中。
可以通过更改两个设置来更改此默认位置。首先,将 useDefaultDeploymentRoot 设置为 False。然后为默认文件夹指定新值。
例如,将:
<useDefaultDeploymentRoot type="System.Boolean">True</useDefaultDeploymentRoot>
更改为:
<useDefaultDeploymentRoot type="System.Boolean">False</useDefaultDeploymentRoot >
<userDeploymentRoot
type="System.String">C:\My Documents\Visual Studio\Projects\MyResults</userDeploymentRoot>
<runDeploymentRoot type="System.String" />
更改代码覆盖率检测位置并指定其他密钥文件进行重新签名
在测试运行配置编辑器中,可以选择要检测的项目以启用代码覆盖率。此外,还可以指定是否就地检测这些项目,并且可以指定检测这些项目后重新签名具有强名称的程序集所使用的密钥文件。
这些设置应用于整个测试运行,这意味着它们应用于所有程序集。如果要对单独的程序集使用不同的设置,在测试运行配置 XML 文件中必须这样做。
在本示例中,有两个代码覆盖率二进制文件:ClassLibrary1.dll 和 ClassLibrary2.dll。例如,可以指定应该就地检测 ClassLibrary1.dll,但不应该就地检测 ClassLibrary2.dll。还可以指定用 Library1.snk 检测后要重新签名 ClassLibrary1.dll,用另一个密钥文件 Library2.snk 检测后重新签名 ClassLibrary2.dll。
下面的 XML 说明如何操作。此处显示的元素(每个元素都表示一个程序集)是 <codeCoverageItems> 元素的子元素。
<element type="Microsoft.VisualStudio.TestTools.Common.CodeCoverageItem">
<binaryFile type="System.String">bin\Debug\ClassLibrary1.dll</binaryFile>
<keyFile type="System.String">Library1.snk</keyFile>
<pdbFile type="System.String">bin\Debug\ClassLibrary1.pdb</pdbFile>
<instrumentInPlace type="System.Boolean">True</instrumentInPlace>
<outputDirectory type="System.String" />
</element>
<element type="Microsoft.VisualStudio.TestTools.Common.CodeCoverageItem">
<binaryFile type="System.String">bin\Debug\ClassLibrary2.dll</binaryFile>
<keyFile type="System.String">Library2.snk</keyFile>
<pdbFile type="System.String">bin\Debug\ClassLibrary2.pdb</pdbFile>
<instrumentInPlace type="System.Boolean">False</instrumentInPlace>
<outputDirectory type="System.String" />
</element>