Guest User

Guest User

  • Tech Writer
  • 2.1k
  • 472.6k

How to create unit test cases for user input in C#?

Feb 16 2020 11:54 PM
Hi Team
 
I want to create unit test for user input, anyone who can help me please do share the information with me if you can, thanks mates or examples to do this as i never used them before for console app in user input for number less than 5 and its output  for that number.
  1. // Program accept number less than 5 or more and make its output difference.  
  2.   
  3. using System;    
  4.   
  5. public class UserApp    
  6. {    
  7.     public static void Main()    
  8.     {    
  9.             string[] seperators = {","" "";""."};    
  10.             int num2;    
  11.             Console.WriteLine("Input numbers over 10:");    
  12.   
  13.             string[] splitArray = Console.ReadLine().Split(seperators, StringSplitOptions.RemoveEmptyEntries);    
  14.             foreach (string num in splitArray)    
  15.             {    
  16.   
  17.             if(Int32.TryParse(num, out num2) == true)    
  18.             {    
  19.                 if (num2 < 10)    
  20.                 {    
  21.                     Console.WriteLine(num + " is smaller than 10");    
  22.                 }    
  23.             }    
  24.             else    
  25.             {    
  26.                 Console.WriteLine(num + " is not a number...");    
  27.             }    
  28.             }    
  29.         }    
  30.   
  31.     }   
 

Answers (3)