Unit Testing 'SearchArray'

In this lab, we will attempt to thoroughly unit test the sample class SearchArray.

  1. Open the LabAssignments project.
  2. Create a new package called lab5.
  3. Create a new class, SearchArray.
  4. Copy the code from here into this new class.
The class implements a linear search for an integer in an array. The code includes two methods and a constructor:
  1. public SearchArray(int[] array, int minVal, int maxVal)
    The constructor takes in an integer array to be searched on as its first argument. The second and the third arguments specify the inclusive range of valid values for all elements of the array.

  2. public void search(int x)
    The search method implements the linear searching logic. The input argument is the number to be searched for in the array.

  3. public static void main(String[] args)
    Many developers prefer writing the unit testing code for a class inside that class's main method. The main method here also does the same by containing all the test cases. Please note that the entry point to your code should still be the main method inside your *Driver class