COMP5028 Object Oriented Analysis and Design Semester 2, 2005 1 Laboratory session Five Storie Dixson 432 A,B Wednesday Aug.31, 2005 School of Information Technologies The University of Sydney Java recap and JUnit introduction Objective • Recap java programming • Experience JUnit through unit test writing • Prepare for the study of JUnit structure Tasks A. Given the very simple implementation of shopping cart system (shopping.jar) Develop a JUnit test for the following tests 1. Add a product to the cart Precondition: A cart is created Postcondition: The balance of cart has been updated and the number of items been updated. 2. Remove a product from the cart Precondition: A cart is created, the product is in the cart Postcondition: the balance of cart has been updated and the number of items been updated 3. Remove an unknown product from the cart Precondition: A cart is created, the product is not in the cart Postcondition: a ProductionNotFoundException is raised 4. Empty the cart Precondition: A cart is created, some product is inside Postcondition: The shopping cart status is empty. Make sure to write a setUp method to build a collection of objects. Each run of a test performs the following steps: setUp(); testXXX(); tearDown(); Default implementation of setUp() and tearDown() is doing nothing. The prediction section of each test tells you what objects are required for a test and the postcondition section tells you what you need to compare or check for each test. You can find a set of assert methods from here: http://junit.sourceforge.net/javadoc/junit/framework/Assert.html COMP5028 Object Oriented Analysis and Design Semester 2, 2005 2 B. Compile and run your test using different TestRunner. Before compiling and running your test, check if the CLASSPATH variable contains “%JUNIT_HOME%/junit.jar”. If it is not in the CLASSPATH variable, you need to specify it while compiling and runing your test using the “- cp …/junit.jar” option. C. If you have methods setUp(), testAdd() and testEmpty() defined in a test case in the given order. In which order does a test runner call them?