使用 TFS/测试中心进行参数化功能测试?

发布于 01-05 12:16 字数 283 浏览 3 评论 0原文

我正在尝试利用 TFS 测试用例的功能,它允许用户向测试用例添加参数。但是,当我设置普通的单元测试(这将成为我的功能/集成测试)并使用插入参数功能时,我似乎无法访问参数数据。据我所知,这个参数化似乎仅适用于编码的 UI 测试。

虽然我可以在测试中使用 [DataSource] 属性编写数据驱动的单元测试,但这意味着需要一个单独的位置来管理测试数据,可能需要一个新的 UI 等。这并不可怕,但不是最佳的。理想的情况是通过测试中心管理一切,但我一生都无法找到如何在单元测试中获取这些数据的描述。

我错过了一些明显的东西吗?

I'm trying to leverage the functionality of the TFS Test Case, which allows a user to add parameters to a test case. However, when I set up a plain vanilla Unit Test (which will become my functional / integration test), and use the Insert Parameter feature, I just don't seem to be able to access the parameter data. From the little I can find, it seems as if this parameterization is only for coded UI tests.

While it's possible for me to write a data driven unit test with the [DataSource] attribute on the test, this would mean a separate place to manage the data for the testing, potentially a new UI, etc. Not terrible but not optimal. What would be ideal is to manage everything through Testing Center but I cannot for the life of me find a description of how to get at that data inside the unit test.

Am I missing something obvious?

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

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

发布评论

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

评论(1

你怎么这么可爱啊2025-01-12 12:16:10

要么我不明白你的问题,要么你自己回答了:-)。让我解释一下:

单元测试和编码 UI 测试(事实上,大多数基于 MSTest 的测试)都利用相同的 [DataSource] 基础设施。这样,测试就可以参数化,而不需要将参数数据嵌入到测试本身中。

VS 2005 和 VS 2008 基本上提供数据库(文本、XML 或关系数据库)作为有效的测试数据源。 VS 2010(和 Microsoft 测试管理器)引入了一种新的数据源:“测试用例数据源”,它会自动插入到从测试用例记录生成的编码 UI 测试中。

但是没有什么可以阻止您对自己的单元测试执行相同的操作。我认为下面的工作流程可能适合您:

  1. 在 MTM 中创建一个测试用例;
  2. 添加您的参数和数据行;
  3. 保存您的测试用例。记下工作项 ID(您将需要它);
  4. 创建单元测试并将以下属性添加到方法标头:

    [DataSource("Microsoft.VisualStudio.TestTools.DataSource.TestCase", "http://my-tfs-server:8080/tfs/my-collection;My-Team-Project", "WI# “,DataAccessMethod.Sequential),测试方法]
    
  5. 在上面的属性中,将 WI# 替换为 #3 中的工作项 ID;< /p>

  6. (可选)在 Visual Studio 中,转到测试菜单并单击 Windows |测试视图。选择您刚刚创建的单元测试,右键单击它并“将测试关联到测试用例”。指向在 #3 中创建的相同测试用例工作项,现在您将手动测试用例转变为自动测试用例。注意:当您自动化测试时,您不能再从 MTM 手动运行它。您需要实验室管理(以及配置为能够运行自动化测试的环境)才能安排和运行自动化测试用例。

Either I didn't understand your question or maybe you answered it yourself :-). Let me explain:

Both Unit Tests and Coded UI Tests (in fact, most MSTest-based tests) leverage the same [DataSource] infrastructure. That way, tests can be parameterized without the need of embedding the parameter data in the test itself.

VS 2005 and VS 2008 basically offered databases (text, XML or relational ones) as valid test data sources. VS 2010 (and Microsoft Test Manager) introduced a new kind of data source: a "Test Case Data Source", which is automatically inserted in a Coded UI test generated from a test case recording.

But nothing prevents you from doing the same to your own unit tests. I think the workflow below could work for you:

  1. Create a test case in MTM;
  2. Add your parameters and data rows;
  3. Save your test case. Take note of the work item ID (you're gonna need it);
  4. Create your unit test and add the following attribute to the method header:

    [DataSource("Microsoft.VisualStudio.TestTools.DataSource.TestCase", "http://my-tfs-server:8080/tfs/my-collection;My-Team-Project", "WI#", DataAccessMethod.Sequential), TestMethod]
    
  5. In the attribute above, replace WI# with the work item id from #3;

  6. (Optional) In Visual Studio, go to the Test menu and click Windows | Test View. Select the unit test you just created, right-click it and "Associate Test to Test Case". Point to the same test case work item created in #3 and now you turned your manual test case in a automated test case. NOTE: When you automate a test you can no longer run it manually from MTM. You need Lab Management (and an environment configured as being able to run automated tests) in order to schedule and run an automated test case.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文