Common Test Cases for Integer Array and Strings

Integer Array

  • Check for null input array
    • passing null to the function call

findMid(null); // expecting valid array elements

check : if(array != null)

  • Check for validity of data type
    • passing improper data type to the function call

char[] ch = new char[10];

findMid(ch); //expecting an integer array

check: if(array instanceof int[])

  • Check for no valid elements
    • passing a valid integer array with no proper values for the function
    • This can be considered as one of the input and this check is debatable

int[] val = new int[10];

findMid(val); //expecting a valid input array of length 3

check: if(array.length > 3)

  • Check for single elements
    • passing an array with single element in it

int[] val = {1};

findMid(val); // expecting at least 3 elements

check: if(array.length > 3)

  • Check for all positive numbers
    • This is a positive testing with proper values for the array elements

int[] val = {1,2,3,4,5}

check: if(array[index] > 0)

  • Check for all negative numbers
    • pass negative numbers for the array inputs
    • your function should consider negative values also

int[] val = {-11,-12,-13,-4,-5}

check: if(array[index] < 0)

  • Check for duplicate elements
    • pass duplicates and see how the function responds
    • you function should handle duplicates

int[] val = {-11,-11,0,0,1,1}

check: if(array[index] != array[index+1]) // in sorted adjacent duplicates

  • Check for positive and negative number combinations
    • pass combinations of negative and positive values

int[] val = {-11,7,5,-13,0,1,21,-31}

  • Check for Minimum and Maximum overflow
    • pass value that is over the integer max or min value
    • your function should handle overflows

int[] val = {2147483647,65535 ,–2147483648,4294967295};

check: if(array[index] > Integer.MAX_VALUE)

if(array[index] < Integer.MIN_VALUE)

  • Check for Array Index Overflow
    • sometimes array index overflow arises if you are checking for a value that is referring to an invalid index in an array
    • your function should not result in array index overflow and you should handle it

for(int i =0;i<array.length;i++){

if(array[i] == array[i+1]) //array index overflow for array[i+1]


  • Check for ordering / non ordering
    • some times you might want to check if the array is sorted or not before processing further. in case of Binary Search in an array


  • Check for null input
    • passing null to the function call

check: if(str != null)

  • Check for “” for string as input
    • passing no value to the string

check: if(!str.equals(“”))

  • Check for single character
    • passing single character to the string

check: if(str.length > 3) //expecting minimum of 3 character in the input string

  • Check for case sensitivity
    • you will have to check for case sensitive for the function involving character manipulations

check: if(str.charAt(index) >= 65 && str.charAt(index) <= 90 ) // upper case

if(str.charAt(index) >= 97 && str.charAt(index) <= 122 ) // lower case

  • Check for digits
    • you will have to limit the characters to digits for integer calculations considering only 0 to 9

check: if(str.charAt(index) >= 48 && str.charAt(index) <= 57)

  • Check for special characters
    • you will have to consider only special characters at times in a function
    • some common special characters are space (32), comma (44), colon (58), semicolon (59) etc. for others you can look up the ASCII table and get the corresponding values

check: if(str.charAt(index) == 32 || str.charAt(index) == 44 || str.charAt(index) == 58 || str.charAt(index) == 59)

  • Check for duplicate characters
    • consider duplicate character presence consecutively.

check: if(str.charAt(index) == str.charAt(index + 1))

  • Check for ASCII or Unicode characters
  • process for ASCII or Unicode according to the need

check: if(str.getBytes( “UTF-8” ))

  • Check for index out of bound access
    • look for index out of bound when using charAt() function


  • Check if the function returns a value
    • sometimes we tend to have a return statement which is inside an if clause but forget to add a default return statement
  • Check for base case of the problem first
    • some of the base case for the problem is to be added at the top of the function to by pass additional checks

These are some of the basic test cases to be considered for most of the functions that you write in java or any other languages

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: