2014-09-26 44 views
0

我正在重写一个有大量单元测试的解决方案,其中许多测试在不同的实体上完成同样的事情。在抽象类中定义的TestMethod不在测试资源管理器中

我试图重构测试来定义默认实现,但我遇到了问题。

我没有看到在测试资源管理器中的BaseTestClass中声明TestMethod的测试。 我错过了什么吗? 理想情况下,我会从基础和每个具体实现的具体类看到一套完整的方法。

这是我有:

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 


} 

回答

0

单元测试将不会运行,除非他们明确地与TestMethod的属性声明。如果你想避免必须添加属性到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() 
    { 

    } 
} 
相关问题