Ken*_*enn 5 c# xml datasource data-driven-tests
我正在使用C#VS2008中的Xml数据源编写数据驱动的单元测试.
属性看起来像这样,一切都很棒.
[DeploymentItem("HtmlSchemaUrls.xml")]
[DataSource("DataSource", "Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\HtmlSchemaUrls.xml", Microsoft.VisualStudio.TestTools.WebTesting.DataBindingAccessMethod.Sequential, "URL")]
[DataBinding("DataSource", "URL", "URL_Text", "DataSource.URL.URL_Text")]
[TestMethod]
Run Code Online (Sandbox Code Playgroud)
我想扩展Microsoft.VisualStudio.TestTools.DataSource.XML数据源的功能,最好通过App.config进行配置.例如,一个bool,当我运行Xml文件中的所有行时为true,而当为false时,我只运行一个.
我不想在测试用例本身中执行此检查 - 我有1000个具有此要求的测试用例.
任何有关如何实现这一目标的指导都将非常受欢迎.
小智 1
使用 AssemblyInitialize 从某个测试集存储库复制 XML 测试集。
1 - 这样,您不需要 [DeploymentItem("HtmlSchemaUrls.xml")]
2 - 不只是复制它,而是创建一个包含需要测试的记录的新文件(使用参数化的 xsl ?)
3 - 的所有参数该操作可以存储在您的 app.config 中
缩短的示例(使用简单的副本来准备数据驱动的测试用例环境:
[AssemblyInitialize()]
public static void AssemblyInit(TestContext context)
{
...
string strRelocatedTestCaseFile =
Path.Combine(TheToolBox.ShortPath(AppDomain.CurrentDomain.BaseDirectory),
"TestCase.xml");
if(!string.IsNullOrEmpty(strTestCaseFile))
{
string strMessage = "Copying TestCase input file: '" +
strTestCaseFile + "' to '" + strRelocatedTestCaseFile + "'";
Console.WriteLine(strMessage);
File.Copy(strTestCaseFile, strRelocatedTestCaseFile, true);
}
}
Run Code Online (Sandbox Code Playgroud)