B15 Informatik 3 (Info3)

Website of Prof. Dr. Barne Kleinen, Professor for Media Informatics (Bachelor/Master) at HTW Berlin

7 - Testing

     <prev next>

Test Button Test Button in Car. Foto by Mike Roberts

Pre-Lab

1. Read about Closed- and Open-Box Tests.

I chose “Closed- and Open-Box Tests” as a more inclusive replacement for the terms “Black- and White-Box” Tests (why?). I could not find a general agreement on the best replacements, so I chose this terms as I think they are also even a better metaphor for the strategies to find test cases they describe:

  • Closed-Box Testing is a strategy to find Test Cases without the need to (or beeing able to) look in the Source Code (“Software-Box”), that is, usually based on the specification and the in- and outputs of a system. see Wikipedia on black-box testing
  • Open-Box Testing is a strategy that considers the internal structure of the Software to find useful test cases. Wikipedia on White-Box Testing, Article on geeksforgeeks)

2. Prepare the Source Code.

A. Closed-Box and Open-Box Testing

Remember, Closed- and Open-Box Testing is a strategy to find appropriate test cases. While some of the examples in these exercises operate on an input set so small it would allow for simply testing on all possible inputs, this exercise is about finding the most effective test cases, as test suites should be kept as small and fast as possible.

This exercise is about defining test cases (and finding bugs). You can do the tests by hand or use the provided examples how to test with pytest. If you use automated tests, make sure that all tests succeed, and mark found bugs with xfail.

  1. Getting started: Give the equivalence classes for testing a method that determines the absolute value of an integer using the closed-box methodology. Don’t peek at the code yet! Now check out absolute.py in the repository and give test cases covering each branch for a open-box test. Define suitable test cases based on your analysis.

  2. closed-box test: Look at the grading scale at the bottom of the page (Which is not the grading scale for this course). Give the equivalence classes for a program that loops until a “-1” is entered, asking for the number of points on this scale, prints the appropriate letter grade (A-F), and then prints the average number of points when “-1” has been entered. Develop one test case for each equivalence class. Test your test cases with GradingScale.class - this is a java programm. No fair decompiling the class! Report on the results. Did you find any errors?

  3. open-box test / path coverage: Examine the code for TaxTime.py. Draw a code graph of the main class! How many independent paths are there? What are the conditions that cause each of the paths to be taken? Draw up a table giving you an overview of the conditions. Give test cases that exercise each path. Are there any errors in the program (besides the size of the tax bite)?

  4. Reflection Reflect on the differences of the two strategies to find test cases.

Grading Scale (Points = Procent)

PointsGradeECTSPointsGradeECTS
95-1001,0A65-693,0C
90-941,3A60-643,3C
85-891,7B55-593,7D
80-842,0B50-544,0D
75-792,3B0-495,0F
70-742,7C

B. Test Driven Development

Your task is to develop deletion in and reversion of a linked list data structure with a test driven approach. I’ve prepared tests that you can implement (make green) one-by-one - therefore it’s not really full TDD (Test Driven Development), as you don’t need to write the tests yourself. See the github repostitory..

The tests are already there in a order in which I think they should be implemented, use pytest -x to see only the next failing test.

For the bored: Refactor your Code after the Tests are running, and experiment with different implementations for deletion in and reversion of a list.

C. Lab Writeup

Submit your Report as PDF to moodle, with a link to a repository for the source code.

Why I replaced the terms

Why these terms are problematic is described here and here. There seems to be no consensus about the best replacement, as it is the case for other terms, e.g. with the new name “main” for the main branch in git, which has been enforced by githubs change to main in 2020.