SDA SE Wiki

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

User Tools

Site Tools


Assignment 11: Testing

Release date: Tuesday, 26.06.12 - Due date: Monday, 03.07.12, 23:59

Task 01: Dual Choice Questions, Testing

4 points

Decide whether the following statements are correct or wrong. Give the answer and a short explanation (1-2 sentences) in a text file.

Evaluation: For this assignment you get 0,5 points for every correct answer with a reasonable explanation. During the final exam you get +1 point for every correct answer and -1 point for every incorrect answer. The minimal number of points for each of the section is 0, this means e.g. giving three incorrect answers in the first block does not influence the points for the second block.

Correct Wrong Statement
Black box testing makes use of equivalence classes and the tests should always be written by the programmers themselves, because they know best what is inside the black box.
Evaluation scenarios gathered during requirements elicitation are meant to be a basis for client acceptance tests.
If you can get full statement coverage for a method, you can also get full branch coverage for this method.
If a method contains 8 if-statements (and no other conditionals), you might need 256 test cases to achieve full path coverage, but not more than 9 test cases to achieve full basis path coverage.
Correct Wrong Statement
The Bottom-up testing strategy employs stubs to simulate components.
Expected results are sometimes called Test Oracle.
The cyclomatic complexity metric provides the number of test cases needed for the basis path test coverage.
Mocks simulate components that are called by the tested component and check expected behavior.

Task 02: White-Box testing

6 points

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

<code java|h The Sort Method> 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

} </Code>

  1. Draw a control flow graph for the above method.
  2. Give an example input that achieves a statement coverage and write down the path. (E.g. like “input = [4], path = start → 1 → 2 → 14 → end”)
  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 path.
  5. Formulate a small method, which needs two different tests to cover all branches.

Task 03: Black-Box Testing, Triangle Classification

4 points

This is a variation of the self-assessment from the classical book from Glenford J. Myers “The Art of Software Testing”.

Your task it to enumerate meaningful equivalence classes with representative test data and expected results for a method specified as follows:

[A method has three integer parameters representing] the lengths of the sides of a triangle. The [method returns a code] that states whether the triangle is scalene1), isosceles2), or equilateral3).

(As this specification only allows integers for the side lengths, you might guess that this author has a more elementary understanding of triangles. So, don't expect this author to consider triangles that just consist of one point to be triangles.)

If you find concrete code helpful, you may have a look at the following: <code java|h Interface for a class implementing this function|h> package triangles;

import static triangles.TriangleKnowledge.TriangleKind.*;

public class TriangleKnowledge {

/**
 * For the definitions of the different kinds of triangles you may consult
 * for example http://en.wikipedia.org/wiki/Triangle#Types_of_triangle
 */
public static enum TriangleKind {
	EQUILATERAL, EQUIANGULAR, SCALENE, ISOSCELES, OBLIQUE, ACUTE, OBTUSE, RIGHT_ANGLED, NOT_A_TRIANGLE
}
public boolean isTriangleOfKind(int a, int b, int c, TriangleKind kind) {
	return false;
}
/**
 * Returns the most specific triangle kind based on the lengths of the
 * sides. Possible values are: EQUILATERAL, SCALENE, ISOSCELES,
 * NOT_A_TRIANGLE
 */
public static TriangleKind kindOfTriangleByLengthsOfSides(int a, int b, int c) {
	return null;
}
/**
 * Returns the most specific triangle kind based on the internal angles.
 * Possible values are: EQUIANGULAR, OBLIQUE, ACUTE, OBTUSE, RIGHT_ANGLED,
 * NOT_A_TRIANGLE
 */
public static TriangleKind kindOfTriangleByInternalAngles(int a, int b, int c) {
	return null;
}

} </Code>


If you like to practice Test-First development, you may try to implement kindOfTriangleByLengthsOfSides Test-First (for additional 2 points 8-) ). This method is much easier than the contains method from the previous assignment and therefore a better candidate for a first experiment in Test-First.

Task 04: Black-Box Testing (optional)

4 points

In this task we revisit Task 04 of Assignment 10 from the perspective of systematic Black-Box testing. It is again about testing the contains method. Even if you did not manage to identify the correct implementation during the last assignment, it might be worth to try it again.

  • Find and write down criteria for equivalence classes of test cases for a black box test of this method. You might want to draw some images to illustrate your answers.
  • Write down a short justification why your criteria are good.
  • Pick some representatives for each of the equivalence classes and write some tests to find the only correct implementation.
  • If you have good tests from the last assignment, you might want to restructure them.
  • Now you should be able to find the correct method, if you haven't already.
1)
no two sides are equal
2)
exactly two sides are equal
3)
all sides are equal
teaching/lectures/oosc/2012/assignment_11.txt · Last modified: 2018/05/09 01:59 (external edit)

SEWiki, © 2021