简体   繁体   English

不是在测试资源管理器中的Abstract类中定义的TestMethod

[英]TestMethod defined in Abstract class not in Test Explorer

I'm rewriting a solution that has a bunch of unit tests, many of which do the exact same thing on different entities. 我正在重写一个具有大量单元测试的解决方案,其中许多单元测试在不同实体上执行的操作完全相同。

I'm trying to refactor the tests to define default implementation, but I'm running into issues. 我正在尝试重构测试以定义默认实现,但是遇到了问题。

I'm not seeing the tests declared TestMethod in the BaseTestClass in the Test Explorer. 我在测试浏览器的BaseTestClass中没有看到声明为TestMethod的测试。 Am I missing something? 我想念什么吗? Ideally I'd see a complete set of methods from the base and the concrete class for every concrete implementation. 理想情况下,对于每个具体的实现,我都会从基础和具体的类中看到一整套方法。

Here's what I have: 这是我所拥有的:

public Interface SomeTestInterface
{
  ... signatures of methods with are required...
  public void TestConnection();

}

[TestClass]
public abstract class BaseTestClass : SomeTestInterface
{
  .. a mix of default implementation and abstract methods

  [TestMethod]
  public void TestConnection() {
  AssertIsTrue(operator.TestConnection());

  }

  [TestMethod]
  public abstract void TestQuery();

}

[TestClass]
public class ConcreteClassA : BaseTestClass
{
  ... overriding of abstract methods


}

The unit tests will not run unless they are explicitly declared with the TestMethod attribute. 除非使用TestMethod属性明确声明了单元测试,否则它们将不会运行。 If you want to avoid having to add the attribute to every implementation of TestQuery could do something like this: 如果要避免将属性添加到TestQuery的每个实现中,可以执行以下操作:

public interface SomeTestInterface
{
    void TestConnection();
}

[TestClass]
public abstract class BaseTestClass : SomeTestInterface
{
    [TestMethod]
    public void TestConnection()
    {

    }

    [TestMethod]
    public void TestQueryBase()
    {
        TestQuery();
    }

    public abstract void TestQuery();
}

[TestClass]
public class ConcreteClassA : BaseTestClass
{
    public override void TestQuery()
    {

    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM