Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
COMP5028 Object Oriented Analysis and Design  Semester 2, 2004 
 1
 
 
Laboratory session Ten  
Storie Dixson 432 A,B 
Wednesday Oct 13, 2004 
School of Information Technologies 
The University of Sydney 
 
Objective 
• Practice JUnit  
• Learning to write test cases and generate test results using the TestRunner 
Tasks 
  
A. Review the SimpleTest.java sample given in the lecture and ensure that you 
are able to compile and run the JUnit test. The source code can be found under 
C:\Program Files\junit3.8.1\junit\samples 
B. Given the very simple implementation of shopping cart system (shopping.jar) 
Develop a JUnit  test for the following test cases (you should create a test 
suite to run all of them once.): 
1. Add a product to the cart  
Postcondition: The balance of cart has been updated and the number of 
items been updated. 
2. Remove a product from the cart 
Precondition: 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: The product is not in the cart 
Postcondition: a ProductionNotFoundException is raised 
Hint: you need to use the try/catch block and use the fail method 
rather than assert to fail this test if no such exception  is caught. 
4. Empty the cart 
Postcondition: The shopping cart status is empty. 
C. Compile and run your test using different TestRunner.