SDA SE Wiki

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

User Tools

Site Tools


( Object Oriented Programming ) - ( Black Box Testing ) - ( Small Refactoring ) - ( Refactoring the Three Key Cup App )

Black Box Testing

Theory

  • Imagine you have to test the class Triangle, whose source code you do not know.
  • The class's only public method of interest is Triangle.contains(Triangle t) and it is supposed to check if the triangle contains some other triangle t. For example the green triangle on the right contains the red one, i.e. greenTriangle.contains(redTriangle) should be true. On the other hand the red doesn't contain the green one, i.e. redTriangle.contains(greenTriangle) should be false.

Preparation

To solve the following task we recommend to use one or both of the following preparations.

Test-First Implementation

You may optionally implement the contains method yourself in a Test-First manner1). You don't need to do it, but this will strongly increase your chances to solve the task. Finding the correct implementation is not that easy. The main point of this preparation is to get some experience with finding test cases.

Test Plan: Equivalence Classes

  • Find and write down criteria for equivalence classes of test cases2) 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 verifying your expectations for this example.

Debunk the Faulty Implementations

Your company decided that it is too difficult3) to develop the contains(..) method within the company. So they announced that they want to buy an implementation. In response they got 17 implementations, but they doubt that many of them are correct. You got the job to find the implementation that is working. Of course you didn't get the source code, but you are a smart tester. Write some tests to find the implementation your company should actually buy. If you did the optional step, you can use the tests that your produced. Here is your guide to the source code:

  • Clone the repository https://github.com/dsp-de/tutorial-dark-triangles and import it into your workspace.
    [Alternatively you can just download the repository as a zip file (Button on the lower right) and import it.]
    • The folder cls contains the implementations Triangle00 till Triangle16.
    • In the folder tst you find the class geometry.TriangleTest. This test exercises all the implementations using the same test methods for each.4)
  • Run the test.
    • You see some tests failing for the class Triangle14 and Triangle16.5)
    • Review the test methods and decide whether they make sense. If they do, Triangle14 and Triangle16 are out.
  • The test method ifOneTriangleIsVeryLargeAndTheOtherVerySmall is annotated with @Ignore and therefore ignored.
    • Is the test method correct? If yes: Remove the @Ignore annotation and run the tests again.
  • Implement some of your test cases from your plan. That is: Pick one to three representatives for each equivalence class and decide about the expected result. Create the triangles6) and add assertions for the expected results.
    • Run your tests and find out which implementation are wrong.
    • We heard that some implementations have only minor errors, so finding the single correct implementation is probably quite hard.
    • You should be able to reduce the number of implementations significantly.
  • Have fun with this exercise :-)
1)
The rules for Test-First are simple:
  1. Write a test describing some expected behavior of the method.
  2. Run the test and see it failing.
  3. Add just enough code to the method to make the test succeed. Not one line more!
  4. Run the test and see it succeeding.
  5. If you can think of another test or think the implementation is not yet complete, start from 1.
2)
“… try to partition the input domain of a program into a finite number of equivalence classes such that you can reasonably assume (but, of course, not be absolutely sure) that a test of a representative value of each class is equivalent to a test of any other value. That is, if one test case in an equivalence class detects an error, all other test cases in the equivalence class would be expected to find the same error.” (Glenford J. Myers, The Art of Software Testing, 1974, Chapter 4)
3)
They didn't listen to you :-(
4)
There is quite some JUnit 4 and Java Reflection Magic behind the mechanism to run the test for each of the implementations. You don't need to understand that. The only thing to remember is, that you should use the createTriangle(..) method to create triangles. Don't use the constructors directly!
6)
Remember to use the createTriangle(..) method to create triangles!
private/daniel/public/tutorials/black_box_testing.txt · Last modified: 2018/05/09 01:59 (external edit)

SEWiki, © 2021