Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Introduction JUnit is possibly the most popular unit - testing tool for Java code. In this exercise you follow a script that walks you through

Introduction
JUnit is possibly the most popular unit-testing tool for Java code. In this exercise you follow a
script that walks you through testing a sample slice of an application. Some Java coding
knowledge and experience in an Eclipse-based IDE is assumed.
While completing this assignment, you learn how JUnit works. At the end you should be able to
use JUnit without a script and answer questions on JUnit in an exam. You learn:
How to code a run a test class
How to combine test classes into test suite
How to use the JUnit perspective in Eclipse
Notes
Pages 2 to 4 describe the sample code to be tested. The code is identical to the air ticketing
sample you used in the Debugging and CheckStyle assignments.
Be sure to use the startup version code. If you made any changes to the code, download the
file again from eCentennial.
Recall that the purpose of testing is to identify defects, not to fix them. For some of the tests, a
failure is the correct result: a test failure indicates a bug.
Instructions for testing with JUnit start on page 5.
Specifications for the air ticketing prototype
The requirement is for a prototype that implements a system for issuing tickets for seats on an air
flight. The prototype does not include the user interface. For testing purposes do not use the
driver and UI stub classes Manifest or UserPrompter. Instead, test cases can call methods on
the classes listed on the next page directly, passing constant values instead of user input as
arguments.
Simplifying factors for this prototype:
Preconditions state that the passenger has already selected a specific flight on a specific
day.
Invoicing and processing payment are handled by a separate subsystem. The application
calculates the price of a ticket but does no billing.
The prototype airplane has very limited seating of only 14 seats. Row 1 is business class
and has one seat on either side of the aisle: 1A and 1B. Rows 2,3 and 4 are economy
class and have two seats on either side of the aisle: 2A,2B,2C,2D,3A ..3D,4A ..4D.
The standard price for a business class seat is $750 and for an economy seat is $500.
The seating plan number of rows in each class, seats in each row, and seat price -- is
specified by the instances of the enumeration SeatingClass.
No persistent data (databases) are used.
All system output goes to the console (System.out.stdout).
Other requirements
FrequentFlyers are passengers who are members of the airlines frequent flyer club.
They are identified by a membership number and have privileges that are outside the
scope of the prototype.
Employees of the airline cannot also be frequent flyers. They are StaffPassengers and
are identified by employee number.
Members of airline staff get a 50% deduction on the price of seats in Economy class
only. A StaffPassenger who wants to travel in business class is treated like a regular
passenger and pays the full fare.
Only one ticket can be sold for each seat. Overbooking is not allowed.
Design Documentation
The next page has two UML class diagrams showing the main types and associations between
them. These diagrams are for your reference only. Just to fit the page, one diagram is split into
two and, as a result, some classes appear in both diagrams.
Dependencies (method calls and has-a relationships) are shown by dashed-line arrows.
UML class diagram 1 of air ticketing example:
UML class diagram 2 of air ticketing example:
Not shown in these diagrams is the interface Discountable, implemented by the class
StaffPassenger.
Summary of the Types involved in the prototype
You cannot extensively test all of these classes in this exercise. The instructions walk you
through some sample tests. While running these tests you should realize that many more test
cases are required to thoroughly test even this very small prototype.
Instructions
Wherever you see the name Mary Worth in these instructions, substitute your own name.
Do this so that your name appears in the solution code.
1. Download file AirTicketDebuggingStart.jar from eCentennial. You can find it under
Assignment2.
2. Start Eclipse
a. You can use a NEW workspace.
b. Make sure work in the Java perspective.
3. Create a new Java project and call it AirTicketPrototypeTesting.
4. Import the JAR file AirTicketDebuggingStart.jar into the new project:
a. Right-click the project name in the Project Explorer view and select Import ->
General -> Archive File.
b. Browse to the downloaded JAR file and select Open.
c. Make sure the entire contents of the jar are selected, that the Into folder is
AirTicketPrototypeTesting/src and click Finish.
d. In the Package Explorer, verify that the src folder contains three packages:
i. com.cc.airline.passengers
ii. com.cc.airline.ticketing
iii. com.cc.airline.utilities
5. Create a JUnit

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro SQL Server Administration

Authors: Peter Carter

1st Edition

1484207106, 9781484207109

More Books

Students also viewed these Databases questions

Question

List the five steps in the message-sending process.

Answered: 1 week ago

Question

List and explain the four steps in the communication process.

Answered: 1 week ago

Question

Describe how communication flows through organizations.

Answered: 1 week ago