Pergunta

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?

Foi útil?

Solução 2

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.

Outras dicas

If you interpret inheritance using the "is" concept, reading the sentence: "GeneralServerTests IS a BaseServer", then that wouldn't seem to make much sense. So I think your test inheritance model probably needs a bit of review and refactoring.

Now, regarding running the same test against different inputs, you should at data-driven tests:

http://msdn.microsoft.com/en-us/library/ms182527.aspx

You can use a datasource to specify info about the target server, and configure your test code.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top