【问题标题】:Why virtual [TestMethod] with [DataRow] call after override [TestMethod]?为什么在覆盖 [TestMethod] 后使用 [DataRow] 调用虚拟 [TestMethod]?
【发布时间】:2021-04-15 23:11:44
【问题描述】:

我有这个类层次结构

[TestClass]
public abstract class BaseTest 
{
  ...
  [TestMethod]
  [DataRow("TestBase")]
  public virtual void Test_1(string title)
  {...}
}

[TestClass]
public class ChildTest : BaseTest
{
  [TestMethod]
  [DataRow("Child")]
  public override void Test_1(string title)
  {...}
}

之后,我运行我的Test_1 表单class ChildTest,我得到错误,因为[DataRow("TestBase")] 也添加到我的TestCase

如果我只做public new virtualvoid Test_1(string title) 不从[DataRow(...)] 继承[DataRow(...)] 参数class BaseTest

我怎么能禁止继承[DataRow] form ** class BaseTest **?还是我建立了无效的类层次结构?

【问题讨论】:

    标签: c# .net unit-testing mstest


    【解决方案1】:

    我发现只有一个决定了我的问题: 它使用new 关键字作为派生类中的方法

    public new void Test_1(...) {...} || public new virtual void Test_1(...) {...}

    Knowing When to Use Override and New Keywords-msdn

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-07-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-01
      • 1970-01-01
      相关资源
      最近更新 更多