Search code examples
c#unit-testingbase-classtest-class

Use the same TestClass with different base class


I am testing various servers,which has the same model, already tested by unit tests. Now I want to test the real servers (not only general model).

When testing general model I created fake general server with fake adapter, which were defined in the base test class and all the testclasses inherit from it.This made more than hundred tests.

Now I need to use the same test classes but with various base classes(for various real servers). They use the same testing data and have the same results. They differ in some internal approach.

Is it somehow possible to call all the tests so many times as the count of servers is, everytime with different base test class(Server type and constructor)??

example:

[TestClass]
public class GeneralServerTests : BaseServer
{
    [TestMethod]
    public void IsAlive_ChecksInteraction_ReturnsTrue()
    {
        Assert.IsTrue(GeneralServer.Adapter.IsAlive());
    }
    ...
}

The Base test class

[TestClass]
public abstract class BaseServer
{
    protected Server GeneralServer;

    [TestInitialize]
    public void Setup()
    {
        //here I assign the Server constructor,
    }
}

So i need to call the GeneralServerTests class with different Servers.

Hope you understand what i mean :)

any solution?


Solution

  • Ok, I solved it using

    [DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV",|DataDirectory|\ArchiveTestingData.csv", "ArchiveTestingData#csv", DataAccessMethod.Sequential)]

    where all the needed info about the adapters are written.

    Now all the tests run as many times as many adapters are in the file.