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

Assignment

Preparation

  1. Download the source code snippets for this assignment: lab04-testing
  2. Prepare your project like we did it in the first lab (Part 1: Set up the git repository and project). Note that this is now lab04, so make sure you adapt your process to that! Eg. put the project into the correct place on the gitlab server.
  3. In addition to what you’ve covered in class, please have a look at black-box and white-box testing.

Part 1: Equivalence Classes

  1. Using the black-box methodology, what are the equivalence classes for testing a method that determines the absolute value of an integer? Don’t look at the code yet.
  2. Now check out number.js. For a white-box test, what would be test cases covering each branch?
  3. Based on your analysis, define suitable test cases for number.js and implement them with jest in the test folder.
  4. Run your tests: npm test number. Report on the results.
  5. Lint and correct your code: npm run lint test/number.test.js.

Part 2: Black Box Tests

  1. Black-box test: Look at the following grading scale (which is not the grading scale for this course).
PointsGradeLetter Grade
95-1001,0A
90-941,3A
85-891,7B
80-842,0B
75-792,3B
70-742,7C
65-693,0C
60-643,3C
55-593,7D
50-544,0D
0-495,0F

What are 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? Let’s call this program “Grading Scale Calculator”

  1. Define one test case for each equivalence class.

  2. Manually test your test cases by runnig the “Grading Scale Calculator”: node "cliTools/gradingScale.min.js" (The sources of this program - Command Line Interface and Module - are minified JavaScript files - don’t try to make sense of them). Report on the results. Did you find errors in the “Grading Scale Calculator”?

Part 3: White Box Tests / Path Coverage

  1. Examine the code for the program “Tax Time”: cliTools/taxTime.js. Draw a code graph of the main class. How many independent paths are there?

  2. What are the conditions that cause each of the paths to be taken? Draw up a table giving you an overview of the conditions.

  3. Define one test case for each path.

  4. Manually test the test cases by running “Tax Time”: node "cliTools/taxTime.js". Report on your results. Did you find errors in “Tax Time”?

Part 4: Refactoring

  1. Plan (only plan!) how you would refactor “Tax Time” to make it’s functionalities testable with jest. Hint: You would need to separate underlaying functionalities from the view (the part where user interaction happens, or CLI), putting the underlaying functionalities into lib/taxTime.js. But which methods should be in the lib/taxTime.js module? Which field variables do you need?

  2. Implement the test cases from (Part 3, Ex 3) with jest in the test folder. Your tests should test lib/taxTime.js. Run them with code coverage: npm run coverage taxTime. What do you think - is it necessary to reach 100% code coverage?

  3. Now actually refactor “Tax Time” so that your tests pass.

  4. Lint and improve your code: npm run lint "cliTools/taxTime.js" "lib/taxTime.js".

Part 5: Test Driven Development

Your task is to develop deletion and reversion of a simple linked list test driven. 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. You find a stub in node.js. Some tests are already available at node.test.js.

  1. Look at the class Node as a head of a Linked List. Develop the jest unit tests for deleting Nodes (which test cases do you need to check?) and then develop a delete method to make your tests pass. Lint and correct your code: npm run lint lib/node.js.

  2. Then, do the same for reversing the list. That is: Test-driven-develop a method reverse(). This is a bit tricky but doable with just one pass through the single linked list. Stick to the test cases, and give it a try - one node at a time! Don’t forget to lint and correct your code.

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

Results Submission

  • Hand in a link to your repository
  • Hand in a lab report
  • Take part in the oral test on Dec. 10 2020

More info on the Labs page.