B15 Informatik 3 (Info3)

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

Assignment 04: Testing

     <prev next>

Test Button Test Button in Car. Foto by Mike Roberts

Download the source code snippets for this assignment.

Source Code for this Assignment: https://github.com/htw-imi-info3-archive/lab-04-testing

A. Black and White Box Tests

In addition to what we’ve covered in class, please have a look at black-box and white-box testing.

  1. Getting started: Give the equivalence classes for testing a method that determines the absolute value of an integer using the black-box methodology. Don’t peek at the code yet! Now check out absolute.java in the repository and give test cases covering each branch for a white-box test. Define suitable test cases based on your analysis and implement them with JUnit.
  2. Black-box test: Look at the grading scale at the bottom of the page (Which is not the [grading scale for this course]({{ site.BaseURL }}/studies/grading/grading-scale)). 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. White-box test / path coverage: Examine the code for TaxTime.java. 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 Consider the last two examples, especially TaxTime. What makes this programs hard to test? How would you refactor TaxTime to make it testable automatically with JUnit?

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 and reversion of a simple linked list test driven. You can do this either in Java or in Ruby. You find stubs in both languages in the github repostitory..

Create a Class Node as Head of a Linked List and develop a method for deleting Nodes in it test driven, that is, develop the Unit Tests first, as we did in class.

Choose one of the two methods we discussed in class to help with the assertions/expectations - by either creating a helper (e.g. assert.java) or a toString method as in toString.java.

Then, do the same for reversing the list, that is, develop a method reverse() test driven. This is a bit tricky but doable with just one pass through the single linked list (in this method if you use a helper function, and it’s also possible in one true pass through the whole list). Stick to the test cases, and give it a try - one node at a time!

Note that you need to make decisions on the actual interface of the methods and the whole list while writing the test, as well as on how the anchor for the first element is stored and changed if necessary. Write a short note (possibly as comment in the Test Code) why you decided to do it as you did.

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

C. Lab Writeup

Submit your Report as PDF to moodle. If you want to, you can include all source code in a single zip file. You can upload up to two files to moodle - the pdf and the source code zip file.