I have a code of my Save() function, it has only switch statement inside. So basically it saves based on the platform chosen. However I already have tests for UpdateGameState(), SaveForWeb() and SaveForX86() functions. Since Unit Testing rules say, if you have a logic in your function no matter how simple it is, you have to test that function.
public void Save ()
{
UpdateGameState();
switch(Helper.BUILD_TYPE)
{
case Helper.BUILD_FOR_WEB:
SaveForWeb();
break;
case Helper.BUILD_FOR_WIN_X86:
SaveForX86();
break;
default:
Debug.Log("Save method: " + Helper.WRONG_BUILD_TYPE_SELECTED_ERR);
break;
}
}
Also calling test inside a test breaks the isolation rule of tests, so it seems I have to copy the testing logic inside my other tests just to check whether the Save() logic works all the way after SaveForWeb() and SaveForX86().
In these circumstances, how would you test this function?
I can do this in my tests:
Helper.BUILD_TYPE = Helper.BUILD_FOR_WEB;
Where BUILD_TYPE is static but not constant as BUILD_FOR_WEB and BUILD_FOR_WIN_X86.
Aucun commentaire:
Enregistrer un commentaire