MSTest:从未找到的其他程序集中的类继承的测试方法

时间:2011-12-21 14:09:23

标签: unit-testing mstest

我有以下问题。我在一个外部装配中实现了一些单元测试,我在单元测试项目中引用了它。单元测试是作为抽象类实现的,应该在我的单元测试项目中继承(并使用它“激活”)。

当我在项目中继承这些类时,测试方法对我来说是可见的。但由于任何原因,它们不是由Visual Studio运行的。当我用Galio Icarus进行测试时,我看到一条消息告诉“测试......无法找到”。

当我将抽象测试类复制到我的项目中时,测试会被找到并正确运行。

您知道实施单元测试的方法是否有一些限制?在我看来,测试执行有一个逻辑,它不仅可以查找TestClassAttribute,TestMethodAttribute等,还可以检查测试实现是否在同一个程序集中完成。

实现如下:

带有外部测试实现的抽象类:

[TestClass]
public abstract class GeneralGridTestsBase<T> where T : GridParamsBase, new()
{
    [TestMethod]
    public virtual void GetCellSetItems_Unique_CellSetKeys()
    {
        // Test implementation
    }

    // Other tests implemented here
}

在我的测试项目中,我继承了抽象类,并期望测试可见并且“活跃”。

[TestClass]
public class RetailInputGeneralTests : GeneralGridTestsBase<RetailInputParams>
{ }

1 个答案:

答案 0 :(得分:3)

我能够复制它,然后通过覆盖虚拟测试方法并调用基本实现来修复它。这似乎是不必要的,但我想这只是MSTest框架的一个特质:

[TestClass]
public class RetailInputGeneralTests : GeneralGridTestsBase<RetailInputParams>
{ 
    [TestMethod]
    public override void GetCellSetItems_Unique_CellSetKeys()
    {
        base.GetCellSetItems_Unique_CellSetKeys()
    }
}
相关问题