dimanche 31 janvier 2016

How to have initialization method for test methods in separate classes?

Currently, I have a whole bunch of test methods that rely on various assortments of the same testing infrastructure, which is quite costly to create. As a result, I built a test class with an initialization method in which the common infrastructure for the testing is instantiated, like so:

public class CostEngineTests
{
    // some private methods A to F used to build infrastructure 

    [TestInitialize]
    public void Initialize()
    {
         // build a bunch of infrastructure here with A to F
    }

    [TestMethod]
    public void CostEngine1()
    {
        // put my engine-specific infrastructure creation and tests here
    }

    // about 20 more test methods to the same effect
}

But I've been told that this class is simply too big, and each method should be separated into its own class (in a separate file). My first thought would be to just create whatever infrastructure is necessary for each test separately then in each class file, but as a consequence of the infrastructure layers it would crush performance to build a great deal of the same infrastructure over and over when testing the whole group of CostEngines.

So, I believe I still need to have this single initialization method that only runs once before any combination of these (now separated) test classes are run. Is there any nice way to do this?

Aucun commentaire:

Enregistrer un commentaire