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>
{ }
I have following problem. I have some unit tests implemented in a foreign assebly which I reference in my unit test project. The unit tests are implemented as abstract classes and should by inherited (and with it "activated") in my unit test project.
When I inherit those classes in my project, the test methods are visible to me. But for any reason they are not run by Visual Studio. When I run the tests with Galio Icarus I see a message telling "Test ... cannot be found".
When I copy the abstract test classes into my project, the tests are found and run properly.
Do you know whether there are some restrictions for the methods implementing the unit tests? It looks to me that the test executiion has a logic which not only looks for TestClassAttribute, TestMethodAttribute and so on, but also checks whether the test implementation is done in same assembly.
The implementation looks like this:
abstract class with test implementation in foreign assebly:
[TestClass]
public abstract class GeneralGridTestsBase<T> where T : GridParamsBase, new()
{
[TestMethod]
public virtual void GetCellSetItems_Unique_CellSetKeys()
{
// Test implementation
}
// Other tests implemented here
}
In my test project I inherit the abstract class and expect the tests to be visible and "active".
[TestClass]
public class RetailInputGeneralTests : GeneralGridTestsBase<RetailInputParams>
{ }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我能够复制这个问题,然后通过覆盖虚拟测试方法并调用基本实现来修复它。这似乎是不必要的,但我想这只是 MSTest 框架的一个特性:
I was able to replicate this and then fix it by overriding the virtual test method and calling the base implementation. It seems uneccessary but I guess it's just an idiosyncrasy of the MSTest framework: