扩展 Microsoft.VisualStudio.TestTools.DataSource.XML

发布于 2024-08-03 02:57:14 字数 665 浏览 4 评论 0原文

我正在 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]

我想扩展 Microsoft.VisualStudio.TestTools.DataSource.XML 数据源的功能,最好通过 App.config 进行配置。例如,当 bool 为 true 时,我会遍历 Xml 文件中的所有行,当为 false 时,我仅遍历一行。

我不想在测试用例本身中执行此检查 - 我有 1000 个具有此要求的测试用例。

任何有关如何实现这一目标的指导将不胜感激。

I'm writing data driven unit tests using an Xml datasource in C# VS2008.

Attributes look something like this and everything works awesomely.

    [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]

I'd like to extend the capabilities of the Microsoft.VisualStudio.TestTools.DataSource.XML datasource, preferrably configurable through App.config. For example, a bool when true I run through all the rows in the Xml file and when false I run through only one.

I do not want to perform this check in the test case itself - I have 1000s of test cases with this requirement.

Any guidance on how to achieve this would be most appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤星 2024-08-10 02:57:14

使用 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);
  }
}

Use AssemblyInitialize to copy your XML test set from some test set repository.
1 - this way, you don't need [DeploymentItem("HtmlSchemaUrls.xml")]
2 - instead of just copying it, create a new file containing the records you need to test (using parameterized xsl ?)
3 - all parameters for that operation can be stored in your app.config

Shortened example (using simple copy to prepare the data driven test case env:

[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);
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文