【问题标题】:VS2010 Unit testing - rerun the same test with different parametersVS2010 单元测试 - 使用不同的参数重新运行相同的测试
【发布时间】:2011-03-23 15:52:17
【问题描述】:

我有一个单元测试,它的行为取决于传递的参数。 VS 2010 MS 测试框架是否可以使用不同的参数调用相同的测试。 我正在寻找这样的东西:

[TestRun(False)]
[TestRun(True)]
[TestMethod]
public void FooTest(bool a)
{
   RunTest(a);
}

【问题讨论】:

标签: visual-studio-2010 unit-testing mstest


【解决方案1】:

我不知道为什么 Micosoft 决定不在他们的单元测试框架中包含这个功能,每当我搜索它时,我发现对 DataSource 属性的引用可以从外部资源(XML 文件)加载数据、数据库等)

如果您不想使用外部数据源,那么您有两种选择:

  1. 使用 MSTest 可扩展性框架添加 RowTest 支持 - explained here
  2. 我在博客中写过如何使用 PostSharp 创建external data source from the test attributes

如果您已经在使用 VS2010,我建议您使用第一个选项 - Microsoft's code gallery 甚至还有完整的工作代码。

【讨论】:

    【解决方案2】:

    以下页面讲述了如何使用 MSTest 数据驱动测试功能实现相同的目标:http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.dataaccessmethod.aspx

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-10-02
      • 1970-01-01
      • 2017-03-09
      • 2019-04-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多