Jeep87c
Jeep87c

Reputation: 1120

How to run tests from an external assembly

Here's what I'm trying to achieve. I'm providing some code through a nuget and want to also publish a second nuget containing tests to verify the service is working/deployed correctly. This test nuget would contain all the core tests to do so without any modification needed (except through config files).

So here's the base class from Assembly A:

[TestClass]
public abstract class BaseTestClass
{
    [TestCleanup]
    public void TearDown()
    {
        // do some cleanup...
    }

    [TestMethod]
    public void BaseTest()
    {
        // base test code...
    }
}

And now, I want to reference this Assembly A into another Assembly B and do something like this:

[TestClass]
public class ChildTestClass : BaseTestClass
{ }

The problem is, the test explorer doesn't see the BaseTest method. It will only see test methods that are declared in the child class itself. Any test methods from the base class are not discovered properly.

How could I do that?

FYI: it's working fine when I do the same thing but all in the same Assembly/project. I'm using both MSTest and ReSharper test runner. MSTest doesn't show anything but ReSharper sometimes shows the base tests but never run it, even if I'm able to select and run a specific one, it will always run only tests declared in the child class.

Upvotes: 2

Views: 231

Answers (1)

Tim
Tim

Reputation: 2912

Hate to be the bearer of bad news, but simply put you cannot.

Visual Studio does not support this. There is a userVoice item to hopefully add support in the future, but until then you cannot build your tests this way.

http://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/6030736-support-test-inheritance-for-base-classes-in-diffe

FYI official MS response confirming it: https://connect.microsoft.com/VisualStudio/feedback/details/989781

Upvotes: 2

Related Questions