ud494 ยป

JUnit Testing Assignment

Logistics

Remember, anything marked as an Assignment is required and graded.  To find the due date and see where this fits in the course overall, see the schedule.

Assignment Description

Test-driven development is based on the idea of developing test cases for a given functionality before coding the functionality. The developed test cases can then be used to automatically check whether the implemented code correctly implements the functionality.  But before we can really develop in a test-driven way, we need to be able to understand and write good tests.

JUnit is a framework that supports test-driven development by providing infrastructure that helps with encoding and running test cases. JUnit can be downloaded here. There is also provides plenty of information on the web on how to get started with JUnit including various documentation and examples (e.g. JUnit Cookbook).

For this assignment, you will perform the following tasks:

  • Download and install JUnit.
  • Write five JUnit test cases for class VendingMachine.
  • Search the Internet for a coverage tool that integrates with JUnit (and potentially Eclipse, if you want to use Eclipse for this assignment). Some possibilities are EclEmma, eCobertura, CodeCover, and Coverclipse.
  • Run the previously-developed test cases using JUnit and the integrated coverage tool and collect coverage information for the test cases. You should collect statement and/or branch coverage. (Collecting additional types of coverage would get you extra points.)

Submission

You will submit two documents via the quiz:

  • VendingMachineTest.java: A java file containing the JUnit test code itself, with JavaDoc style comments for each test, explaining the test's goal.
  • coverage.txt: A text file containing a coverage report that shows (1) which entities were covered by each of your test cases and (2) the total coverage achieved. Note that the coverage tool you choose may provide this functionality itself, in which case you can simply use the report generated by the tool.

A few tips

  • Do not change VendingMachine to include getter methods or state variables.
  • Do not forget the oracles (assertEquals or assertTrue).
  • Do not test Coin instead of VendingMachine (the 5 test cases must be for class VendingMachine).
  • Do not write irrelevant test cases.
  • Do not duplicate test cases.
  • Do not forget to show coverage for each test case (i.e., not only the total coverage).

Placement in Course

You can find the video introducing the exercise here.