Software Engineering for Smart Data Analytics & Smart Data Analytics for Software Engineering

User Tools

Site Tools

Assignment 10: Testing

Release date: Monday, 27.06.11 - Due date: Sunday, 03.07.11, 23:59

Task 1: Blackbox testing

3 points

Given the following interface

public interface DateParser { 
  * Interprets a date string of the form "day-month-year"
  * Day and Month can have either one or two digits (with leading zero)
  * Year can have two or four digits, two digits represent 21. century dates 
  * If the Month is smaller than 1, January is used, values over 12 are interpreted as December
  * If the Day is smaller than 1, 1 is used, similar the last possible day number is taken for inputs larger than possible.
  * @param input  the date string that should be interpreted
  * @return the interpreted date (with time 12:00:00) or null in case of an invalid input
 java.util.Date parseDate(String input); 
  1. Find at least five different working and five error equivalence classes.
  2. Present for each of your equivalence classes an example input and the result.
  3. In the SVN folder of group00 you find a zip containing the DateParser Eclipse project. This project contains a class and a test for the DateParser interface. Add your examples from subtask 2 as test-cases to the GemaltoDateParserTest JUnit4 class.

Task 2: Whitebox testing

4 points

Given is the following method sort which sorts a field of int variables with a bubble sort.

public int[] sort(int[] list) {           // Nr.
 boolean change = true;                   //  1 
 if (list.length > 1) {                   //  2
  while (change) {                        //  3
   change = false;                        //  4
   for (int i = list.length - 1;          //  5
     i > 0;                               //  6
     i--) {                               //  7
        int i1 = list[i];                 //  8
        int i2 = list[i – 1];             //  9
        if (i1 < i2) {                    // 10
           list[i] = i2;                  // 11
           list[i – 1] = i1;              // 12
           change = true;                 // 13
 return list;                             // 14
  1. Draw a controlflow graph for the above method.
  2. Give an example input that achieves a path coverage and write down the path.
  3. Does this input also achieve a branch coverage? If yes, modify your example to not fulfill this anymore. If no, modify your example to achieve branch coverage. Write down the path sequence for this new input.
  4. How many paths does this method have? Give an input example for each.
  5. Formulate a small method, which needs two different tests to cover all branches.

Task 3: Testing with Stubs vs Mocks

4 points

In this task you will compare the two different testing techniques Stubs and Mock Objects. See also the article Mocks Aren't Stubs by Martin Fowler and the Easymock documentation.

Download the project and import it into an Eclipse workspace. It contains a small part of a CD player software. The class PlayController controls the player's hardware API defined by the interface CDPlayer.

  1. Complete the two unit test classes StubTest and MockTest using the corresponding testing techniques.
  2. Explain the advantages/disadvantages of the two different techniques.

Optional Tasks

How to start

  • Install eclipse.
  • Download tutorial project and import it.
  • Your solutions should be in the folder src.
  • You should never change any class in the tst folder.
  • The tasks are described in more detail in the mentioned files in the tst folder.
  • The first thing you should do is to run the tests1).
  • You will see that 11 of 14 tests are failing 2). This means that we made assertions about the base code that are not true for the current implementation.
  • After you solved all tasks 12 of 14 tests should be successful 3). If you decide to solve even the extra tasks everything should be green 4) and there should be even more tests.

Optional Task 01: Persons and Addresses (Identity vs Equality of Objects)

3 points

After you have solved this task, you should be able to understand and explain:

  • … the difference between the two concepts equality and identity of objects.
  • See X1T01_AddressTest in the package people in the tst folder.

Optional Task 02: Number Generators (Implementing Interfaces)

3 points

After you have solved this task, you should be able to understand and explain:

  • … how you write classes that implement interfaces.
  • … how you write methods that can work on any of these classes.
  • See X1T02_NumberGeneratorTest in the package numbers in the tst folder.

Optional Task 03: Students and Professors are Persons (Class Inheritance)

4 points

After you have solved this task, you should be able to understand and explain:

  • … how you can create subclasses.
  • … how class extension relates to interface implementation.
  • … how you can make use of inheritance to reuse common functionality.
  • See X1T03_PersonsStudentsProfessors in the package university in the tst folder.

Optional Task 04: The University (Using Frameworks)

4 points

After you have solved this task, you should be able to understand and explain:

  • … how to let your classes implement interfaces so that framework classes know what to expect from them.
  • … how to configure framework classes, so that you can extend their behavior without modifying them.
  • See X1T04_StudentTest in the package university in the tst folder.


teaching/lectures/oosc/2011/assignment_10.txt · Last modified: 2018/05/09 01:59 (external edit)

SEWiki, © 2024