mardi 18 juillet 2017

Testing a multifactorial generation tree

I am writing functional testing for a tournament generation process.

So, basically, I set my params, and generate my tree

$setting = $this->createSetting(1, 5, 0, 0,3);
$this->generateTreeWithUI($setting);

With:

protected function createSetting($numArea, $numCompetitors, $team, $hasPreliminary, $preliminaryGroupSize): stdClass
{
    $setting = new stdClass;
    $setting->numArea = $numArea;
    $setting->numCompetitors = $numCompetitors;
    $setting->preliminaryGroupSize = $preliminaryGroupSize;
    $setting->hasPlayOff = false;
    $setting->hasPreliminary = $hasPreliminary;
    $setting->isTeam = $team;
    return $setting;
}


public function generateTreeWithUI($setting)
{

    $this->visit('/kendo-tournaments')
        ->select($setting->hasPreliminary, 'hasPreliminary')
        ->select($setting->isTeam, 'isTeam')
        ->select($setting->numArea, 'fightingAreas')
        ->select(
            $setting->hasPlayOff
                ? ChampionshipSettings::PLAY_OFF
                : ChampionshipSettings::DIRECT_ELIMINATION, 'treeType'
        )
        ->select($setting->preliminaryGroupSize, 'preliminaryGroupSize')
        ->select($setting->numCompetitors, 'numFighters');


    $this->press('save');
}

I when I test, I do:

foreach ($numPreliminaryGroups as $preliminaryGroupSize => $numPreliminaryGroup) {
        foreach ($numAreas as $numArea) {
            foreach ($competitorsInTree as $numCompetitors) {
                $setting = $this->createSetting($numArea, $numCompetitors, 0, 1, $preliminaryGroupSize);// $team
                $this->generateTreeWithUI($setting);
                parent::checkGroupsNumber($this->championshipWithComp, $numArea, $numCompetitors, $numPreliminaryGroup,$preliminaryGroupSize, __METHOD__);
            }
        }
    }

This is a way for me to test all combinations. Because there is no way to say that my generating algorithm will work in all the cases.

What is bothering me right now, is that I must a lot of thing in one test, so when test fails, there is more than one reason for the fail to test. It can be quite hard to understand what is failing.

On the other hand, I could test all params in an independant way ( 1 test by param), so instead of having 1 test with 3 foreach, I should write 3 tests with only 1 foreach. But I won't be able to test all combinations, and that is risky....

So, my question is what is the best approach to test those case?

Aucun commentaire:

Enregistrer un commentaire