Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unit testing MSTest:找不到从位于其他程序集中的类继承的测试方法_Unit Testing_Mstest - Fatal编程技术网

Unit testing MSTest:找不到从位于其他程序集中的类继承的测试方法

Unit testing MSTest:找不到从位于其他程序集中的类继承的测试方法,unit-testing,mstest,Unit Testing,Mstest,我有以下问题。我在国外assebly中实现了一些单元测试,我在单元测试项目中引用了这些测试。单元测试是作为抽象类实现的,应该在我的单元测试项目中被继承(并随之“激活”) 当我在项目中继承这些类时,测试方法对我是可见的。但由于任何原因,它们不是由VisualStudio运行的。当我用Galio Icarus运行测试时,我看到一条消息,告诉我“找不到测试” 当我将抽象测试类复制到我的项目中时,测试被找到并正常运行 你知道实现单元测试的方法是否有一些限制吗?在我看来,测试执行有一个逻辑,它不仅查找Te

我有以下问题。我在国外assebly中实现了一些单元测试,我在单元测试项目中引用了这些测试。单元测试是作为抽象类实现的,应该在我的单元测试项目中被继承(并随之“激活”)

当我在项目中继承这些类时,测试方法对我是可见的。但由于任何原因,它们不是由VisualStudio运行的。当我用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]
公共抽象类GeneralGridTestsBase,其中T:GridParamsBase,new()
{
[测试方法]
公共虚拟无效GetCellSetItems\u Unique\u CellSetKeys()
{
//测试实现
}
//此处实现的其他测试
}
在我的测试项目中,我继承了抽象类,并期望测试是可见的和“活动的”

[TestClass]
公共类RetailInputGeneralTests:GeneralGridTestsBase
{ }

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

[TestClass]
public class RetailInputGeneralTests : GeneralGridTestsBase<RetailInputParams>
{ 
    [TestMethod]
    public override void GetCellSetItems_Unique_CellSetKeys()
    {
        base.GetCellSetItems_Unique_CellSetKeys()
    }
}
[TestClass]
公共类RetailInputGeneralTests:GeneralGridTestsBase
{ 
[测试方法]
公共覆盖无效GetCellSetItems\u Unique\u CellSetKeys()
{
base.GetCellSetItems\u Unique\u CellSetKeys()
}
}

TestClass属性应用于类。修复方法如上所述,您必须重写抽象基上的虚拟方法,即使您所做的只是调用基。我知道这是多余的,但这只是MSTest框架的一个特性。外部程序集,这是二进制还是项目引用?它被引用为二进制(只有DLL可用)。
[TestClass]
public class RetailInputGeneralTests : GeneralGridTestsBase<RetailInputParams>
{ 
    [TestMethod]
    public override void GetCellSetItems_Unique_CellSetKeys()
    {
        base.GetCellSetItems_Unique_CellSetKeys()
    }
}