dimanche 24 avril 2016

Unit testing of a class reading a configuration file

I have a class "Configuration" that has a method "getConfig" that reads a configuration file "config.ini" where I have all the app configs (database credentials and host, some apis keys, .....)

For now I have this unit test that tests if the database entry exists in the config file and at the same time confirms that the array returned by the method "getConfig" has the key "database":

function testConfigFileHasDatabaseEntry()
{
    $configuration = Configuration::getInstance();
    $arrConfig = $configuration->getConfig();
    $this->assertArrayHasKey('database', $arrConfig);
}

I have also another unit test that confirms that "getConfig" returns a variable of type array.

My question is the following: In terms of unit testing best practices, in this case is this test enough to confirm that the function getConfig is well tested or it is better to confirm that every key exists in the config file. I think confirming that all entries are in the config file maybe falls under another category of testing, but I want to be sure.

Let me know what is the best practice in this case.

Thanks

Aucun commentaire:

Enregistrer un commentaire