(Sorry for my english) I'm trying to make a unit test from a code of c++. In the next function (menu) there aren't any parameter into (). But into this funciton there are a scanf,that i would like testing but I haven't any idea how to make it.
Can I test scanf from Unit Test?
Thank you.
Code from function:
void principal::menu()
{
int choice;
system("cls");
printf("\n--------MENU--------");
printf("\n1 : Jugador X");
printf("\n2 : Jugador O");
printf("\n3 : Sortir");
printf("\nTria el tipus de jugador: ");
scanf_s("%d", &choice);
turn = 1;
switch (choice)
{
case 1:
player = 1;
comp = 0;
player_first();
break;
case 2:
player = 0;
comp = 1;
start_game();
break;
case 3:
exit(1);
default:
menu();
}
}
Code from test:
...
TEST_METHOD(menu){
principal p; //this is the class --> not matter now
//test code
}
If the code have a parameter I use the next code:
...
TEST_METHOD(menu){
principal p; //this is the class --> not matter now
//test code
Assert::AreEqual(result, parameter to enter);
}
Aucun commentaire:
Enregistrer un commentaire