Software Testing: Tutorial 2

The purpose of this tutorial is to allow you to become familiar with the first Software Testing Practical, raise any immediate questions you have with your tutor, think about what kind of information you might need to know, and to look at the code you are about to test. You should do the following:

  1. [10 Mins reading + 5 Mins Discussion] Read the practical handout and mark up with any queries you have. Get the tutor to construct an amalgamated list of questions and then try to clear them up — anything that remains a problem should be emailed to Conrad.
  2. [10 Mins reading + 5 Mins Discussion] Take some time to read the code you're about to test — read it looking for features that are not understandable without additional information. As you read, decide what additional information you will need to amass in order to start testing the code. In the discussion you should try to build up a joint list of information you need and then consider where to find it.
  3. [5 Minutes reading the code + 10 Mins Discussion + 5 Mins Discussion] Have another look at the code, this time you should be try to read the code considering what aspects of the code might be hard to test. Then in discussion you should:
    • In the first ten minutes make a list of things you think might be hard to test, then choose two or three and consider what kinds of inputs you would need to give the function to test the behaviour you have identified. Work individually at first and then try to construct an amalgamated list.
    • In the last 5 minutes each individually try to construct an erroneous variant of the toRelativeURL method by changing only one character in the file and then try to work out a test that would uncover the error.

Source extract for toRelativeURL():
/** This method converts an absolute url to an url relative to a given
 * base-url.  The algorithm is somewhat chaotic, but it works (Maybe rewrite
 * it).  Be careful, the method is ".mm"-specific. Something like this should
 * be included in the librarys, but I couldn't find it. You can create a new
 * absolute url with "new URL(URL context, URL relative)".
 */
public static String toRelativeURL(URL base, URL target) {
  // Precondition: If URL is a path to folder, then it must end with '/'
  // character.
  if( (base.getProtocol().equals(target.getProtocol())) &&
    (base.getHost().equals(target.getHost()))) {

    String baseString = base.getFile();
    String targetString = target.getFile();
    String result = "";

      //remove filename from URL
      baseString = baseString.substring(0, baseString.lastIndexOf("/")+1);

      //remove filename from URL
      targetString = targetString.substring(0, targetString.lastIndexOf("/")+1);

    //Maybe this causes problems under windows
    StringTokenizer baseTokens = new StringTokenizer(baseString,"/");
    //Maybe this causes problems under windows
    StringTokenizer targetTokens = new StringTokenizer(targetString,"/");

    String nextBaseToken = "", nextTargetToken = "";

    //Algorithm

    while(baseTokens.hasMoreTokens() && targetTokens.hasMoreTokens()) {
      nextBaseToken = baseTokens.nextToken();
      nextTargetToken = targetTokens.nextToken();
      if (!(nextBaseToken.equals(nextTargetToken))) {
        while(true) {
          result = result.concat("../");
          if (!baseTokens.hasMoreTokens()) {
            break;
          }
          nextBaseToken = baseTokens.nextToken();
        }
        while(true) {
          result = result.concat(nextTargetToken+"/");
          if (!targetTokens.hasMoreTokens()) {
            break;
          }
          nextTargetToken = targetTokens.nextToken();
        }
        String temp = target.getFile();
        result = result.concat(
            temp.substring(temp.lastIndexOf("/")+1,temp.length()));
        return result;
      }
    }

    while(baseTokens.hasMoreTokens()) {
      result = result.concat("../");
      baseTokens.nextToken();
    }

    while(targetTokens.hasMoreTokens()) {
      nextTargetToken = targetTokens.nextToken();
      result = result.concat(nextTargetToken + "/");
    }

    String temp = target.getFile();
    result = result.concat(
        temp.substring(temp.lastIndexOf("/")+1,temp.length()));
    return result;
  }
  return target.toString();
}

Version 1.3, 2010/01/25 13:57:29


Home : Teaching : Courses : St : 2009-2010 

Informatics Forum, 10 Crichton Street, Edinburgh, EH8 9AB, Scotland, UK
Tel: +44 131 651 5661, Fax: +44 131 651 1426, E-mail: school-office@inf.ed.ac.uk
Please contact our webadmin with any comments or corrections. Logging and Cookies
Unless explicitly stated otherwise, all material is copyright © The University of Edinburgh