gpt4 book ai didi

c# - 在 MSTest 中忽略从通用基类继承的测试类

转载 作者:可可西里 更新时间:2023-11-01 03:00:51 30 4
gpt4 key购买 nike

在 MSTest 中创建通用基测试类并从中继承时,我无法运行所有继承类的测试。

Unit test results

BaseDependencyPropertyFactoryTest 位于 Whathecode.PresentationFramework.Tests 程序集中。它是通用基类。 (BaseDependencyPropertyFactoryTest )

两个程序集都有一个继承自该基类的测试,称为 DependencyPropertyFactoryTest。继承类所做的只是传递一个特定类型的参数。

[TestClass]
public class DependencyPropertyFactoryTest
: BaseDependencyPropertyFactoryTest<ASpecificClass>
{
}

似乎只有位于与基类相同的程序集中的继承测试运行。 Whathecode.PresentationFramework.Aspects.Tests 程序集中的继承测试似乎被完全忽略了。

我做错了什么?如果需要,我可以上传所有需要的源代码,但您需要 PostSharp 来进行方面组装。


作为测试,我尝试向方面程序集中的继承测试类添加一个测试,它调用基测试类中的所有测试。

[TestMethod]
public void AllBaseTests()
{
ClrGetterSetterTest();
DependencyPropertyGetterSetterTest();
}

这给出了以下结果。奇怪的是,这个测试被执行了!现在,这可能至少可以作为运行它们的一种方式,但我当然不想每次在基类中添加额外测试时都编辑此测试。

Unit test results after edit

为什么这些基础测试被跳过,为什么指示“中止”?

最佳答案

造成这种情况的原因与泛型无关,而是与不同程序集中的测试有关。

Microsoft Connect 建议描述了问题:"Visual Studio Test (MSTest) and lack of Inheritance support for base classes that resides in different assemblies."它被标记为“已修复”,但在 Visual Studio 2010 中似乎尚未修复,也许它仍需要发布?

这个问题有一个有趣的解决方法:

You can work around this problem by compiling the source file containing the base class into all test projects that wish to derive from that base class. Add the item as a "link" so that you don't end up with multiple copies of the source file for the base class.

这对我有用,而且我不觉得这个解决方法太难看。

关于c# - 在 MSTest 中忽略从通用基类继承的测试类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6002424/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com