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'?
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.
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
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:
Nothing special, but another way of solving the problem by calling base methods is:
Hopefully VS 2012 will fix this problem....