MSTest 中忽略从通用基继承的测试类
在 MSTest 中创建通用基测试类并继承它时,我无法运行所有继承类的测试。
BaseDependencyPropertyFactoryTest 位于 Whathecode.PresentationFramework.Tests > 组装。它是通用基类。 (BaseDependencyPropertyFactoryTest
两个程序集都有一个继承自该基类的测试,称为DependencyPropertyFactoryTest。继承类所做的只是传递特定类型参数。
[TestClass]
public class DependencyPropertyFactoryTest
: BaseDependencyPropertyFactoryTest<ASpecificClass>
{
}
似乎只有位于与基类相同的程序集中的继承测试才能运行。 Whathecode.PresentationFramework.Aspects.Tests 程序集中继承的测试似乎完全被忽略。
我做错了什么?如果需要,我可以上传所有必需的源代码,但您将需要 PostSharp 来进行方面程序集。
作为测试,我尝试向方面程序集中的继承测试类添加一个测试,该测试调用基测试类中的所有测试。
[TestMethod]
public void AllBaseTests()
{
ClrGetterSetterTest();
DependencyPropertyGetterSetterTest();
}
这给出了以下结果。奇怪的是这个测试被执行了!目前,这可能至少可以作为运行它们的一种方式,但当然,我不想每次在基类中添加额外的测试时都编辑此测试。
为什么会跳过这些基本测试,以及为什么指示“中止”?
When creating a generic base test class in MSTest, and inheriting from it, I'm unable to run the tests of all the inheriting classes.
BaseDependencyPropertyFactoryTest is located in the Whathecode.PresentationFramework.Tests assembly. It is the generic base class. (BaseDependencyPropertyFactoryTest<TTestClass>)
Both assemblies have a test inheriting from this base class, called DependencyPropertyFactoryTest. All the inherited class does is passing a specific type argument.
[TestClass]
public class DependencyPropertyFactoryTest
: BaseDependencyPropertyFactoryTest<ASpecificClass>
{
}
Only the inheriting test located in the same assembly as the base class seems to run. The inherited test in the Whathecode.PresentationFramework.Aspects.Tests assembly seems to be ignored entirely.
What am I doing wrong? When desired I could upload all the required source code, but you will need PostSharp for the aspects assembly.
As a test, I tried adding a test to the inherited test class in the aspects assembly, which calls all the tests in the base test class.
[TestMethod]
public void AllBaseTests()
{
ClrGetterSetterTest();
DependencyPropertyGetterSetterTest();
}
This gives the following result. Strangely enough this test is executed! For now this might work as a way to at least run them, but of course I don't want to edit this test each time I add extra tests in the base class.
Why are those base tests skipped, and why the indication 'Aborted'?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
其原因与泛型无关,而是与测试位于不同的程序集中有关。
Microsoft Connect 建议描述了该问题:"Visual Studio Test (MSTest) 以及缺乏对驻留在不同组件中的基类的继承支持程序集。” 它被标记为“已修复”,但在 Visual Studio 2010 中似乎还没有修复,也许它还需要发布?
对于这个问题有一个有趣的解决方法:
这对我有用,而且我不认为解决方法太丑陋。
The cause of this doesn't have to do with generics, but with the tests being in different assemblies.
A Microsoft Connect suggestion describes the problem: "Visual Studio Test (MSTest) and lack of Inheritance support for base classes that resides in different assemblies." It is marked as 'fixed', but doesn't seem to be fixed in Visual Studio 2010 yet, perhaps it still needs to be released?
There is one interesting workaround to this problem:
This worked for me, and I don't find the workaround too ugly.
没什么特别的,但是通过调用基本方法解决问题的另一种方法是:
希望 VS 2012 能够解决这个问题......
Nothing special, but another way of solving the problem by calling base methods is:
Hopefully VS 2012 will fix this problem....
Steven 的答案是将基类源文件添加为链接,然后将其编译到测试 dll 中,这也对我有用。
然而,从 VS 2013 Update 2 开始,出现了“共享项目”的概念,这是一种形式化将源代码从另一个项目拉入您的项目,然后将它们编译为一个项目的想法的方法。
这就是我所做的
至少在 VS2015 Update 2 上,步骤 3 并不像我想象的那么简单。根据这个答案,Visual Studio 没有为您提供一种将共享项目链接到测试项目的简单方法(见图... )。这就是我必须做的:
一直到底部并将其添加到
分组(根据需要修复路径和名称,确保添加Label="Shared"
!):保存并关闭文件
Steven's answer of adding the base class source file as a link and then compiling it into the test dll worked for me as well.
However, starting in VS 2013 Update 2 there is now a concept of a "Shared Project" which is a way to formalize the idea of pulling in source code from another project into your project and then compiling them as one.
Here's what I did
At least on VS2015 Update 2, step 3 isn't as straight forward as I think it should be. Per this answer Visual studio doesn't provide you an easy way to link shared projects to test projects (go figure...). This is what I had to do:
Go all the way to the bottom and add this to the start of the
<Import ...>
grouping (fix path and name as needed, make sure to addLabel="Shared"
!):Save and close the file
此问题已修复,并在 1.1.17 版本中发布:
框架: https://www.nuget.org/packages/MSTest.TestFramework/1.1.17
适配器:https://www.nuget.org/packages/MSTest.TestAdapter/1.1.17< /a>
参考文献:
This has been fixed, and is shipping in the 1.1.17 release here:
Framework: https://www.nuget.org/packages/MSTest.TestFramework/1.1.17
Adapter: https://www.nuget.org/packages/MSTest.TestAdapter/1.1.17
References: