On this page:
Lab 10 Description
Regression tests
Version: 5.2.1

Lab 10

Lab 10 Description

Regression tests

There is no work to be done here - this is just a short write-up on the examples we have shown you in the lecture.

As we build a project we want to make sure that teh new features we have added do not break anything written erlier. For this reason, we often keep re-running the tests that have already successfully passed.

As the number of tests grows, we may divide the tests into sections that pertain to different deatures of the project, and test each section separately. However, we should still design a composite test that will re-run all of them - and possibly give us an option to select some, but not all tests for the next test run.

When designing the labs for this workshop, we created several files with the same class definitions and some methods, with each having a more complete solution. Because of the class name conflicts we could not put them into the same project, unless we hid each iteration of our project development in its own package.

We then designed the following class in the default package:

import java.io.*;

import java.lang.reflect.Array;

 

import tester.Tester;

 

import a1Oceanimperative.ExamplesOceanWorldImp;

import a2BankingData.ExamplesBankingData;

import a3Bankingmethodsbad.ExamplesBankingMethodsBad;

import a4Bankingmethodsnotests.ExamplesBankingMethods;

 

public class ProjectRunner{

 

  static int n;

 

  static Object[] examples = new Object[]{

 

    ExamplesOceanWorldImp.examplesInstance,

    ExamplesBankingData.examplesInstance,

    ExamplesBankingMethodsBad.examplesInstance,

    ExamplesBankingMethods.examplesInstance

 

  };

 

  /**

   * Run the tests in the given <code>Examples</code> class.

   *

   * @param obj an instance of the <code>Examples</code> class

   */

  public static void runTests(Object obj){

    String className = obj.getClass().getName();

    try{

      System.out.println("\n**********************" +

                         "\n* Tests for the class: " + className +

                         "\n**********************" +

                         "\nPress return to start:\n");

      n = System.in.read();

 

      Tester.runReport(obj, false, false);

    }

    catch(IOException e){

      System.out.println("IO error when running tests for " + className +

          "\n " + e.getMessage());

    }

  }

 

  /** main: running the tests */

  public static void main(String[] argv){

    for (int i = 0; i < Array.getLength(examples); i++){

      runTests(examples[i]);

    }

  }

}

We then included in every Examples class the code

public static ExamplesBankingMethods examplesInstance =

                new  ExamplesBankingMethods();

Now our ProjectRunner has access to an inastance of each Examples class and we could control which tests to run by just modifying the contents of the Array examples to decide which tests should run.