Answered step by step
Verified Expert Solution
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 unittesting 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 Eclipsebased 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 to 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
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 seats. Row is business class
and has one seat on either side of the aisle: A and B Rows and are economy
class and have two seats on either side of the aisle: ABCDA DA D
The standard price for a business class seat is $ and for an economy seat is $
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 Systemout.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 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 hasa relationships are shown by dashedline arrows.
UML class diagram of air ticketing example:
UML class diagram 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.
Download file AirTicketDebuggingStart.jar from eCentennial. You can find it under
Assignment
Start Eclipse
a You can use a NEW workspace.
b Make sure work in the Java perspective.
Create a new Java project and call it AirTicketPrototypeTesting.
Import the JAR file AirTicketDebuggingStart.jar into the new project:
a Rightclick 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
AirTicketPrototypeTestingsrc and click Finish.
d In the Package Explorer, verify that the src folder contains three packages:
i com.ccairline.passengers
ii com.ccairline.ticketing
iii. com.ccairline.utilities
Create a JUnit
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started