The function below gets input from the user. I need to test this function using Unit Testing. Can anyone tell me how to test this kind of function which require user input dynamically. Thanks
like boundary value analysis …
numberOfCommands should be (0 <= n <= 100)
public static int Get_Commands()
{
do
{
string noOfCommands = Console.ReadLine().Trim();
numberOfCommands = int.Parse(noOfCommands);
}
while (numberOfCommands <= 0 || numberOfCommands >= 100);
return numberOfCommands;
}
Programmatically hint will be great help!
Create an interface and pass in the interface to receive text. Then, in your unit test, pass in a mock interface that automatically returns some result.
Edit for code details: