Skip to content

FlightTest Documentation

Hailey Fritz edited this page Nov 22, 2023 · 6 revisions

Overview

The FlightTest class is a test class for the Flight class, using the JUnit frameworks for testing.

Class-Level

  • The FlightTest class is called via the Test Suite Class Test Suite and therefore requires no individual instance for the required functionality. The below code showcases how the FlightTest class is referenced and utilized:
@RunWith(Suite.class)
@Suite.SuiteClasses({
      LuggageManagementSystemTest.class,
      PassengerTest.class,
      LuggageSlipTest.class,
      LuggageManifestTest.class,
      FlightTest.class
})
  • This class is used with the Template design pattern as a subclass of the TestTemplate class.

  • The main methods implemented are as follows:

    • testFlightNo()

    • testDestination()

    • testOrigin()

    • testFlightDate()

    • testManifest()

    • testConstructor()

    • testCheckInLuggage()

    • testPrintLuggageManifest()

    • testGetAllowedLuggage()

    • testToString()

These methods are used to test method & attribute naming conventions and types, behaviour and functionality of methods, expected abstractions and inheritance hierarchies of the student's submitted Passenger.java file.

Method-Level

Methods

The below methods are used to test the naming conventions and functionality of the student's submitted Flight class. For each method there is no returned object nor any accepted parameters, however, the use of inherited attributes from the parent class, TestTemplate is used to track its grading, i.e.

  • boolean passed is used to indicate whether a particular test condition is true and therefore the designated mark should be awarded.
  • Class<?> testClass is used to set the class type to Flight to indicate the Flight class is being tested. Note: The inherited attribute int passedTestMarks is decremented for each test that fails, thereby determining the mark to be awarded for the "Passes JUnit Tests" section.

A Feedback object is created at the end of each test, reflecting the appropriate feedback response and mark to be displayed from the test result.

  • @Before public void init(): This method reinitializes the requisite variables before each test annotated with @Test
mark = 0;
response = "";
declaredOnly = false;
passed = false;
field = null;
testClass = Flight.class;
flight1 = new Flight("POS123", "JFK", "POS", LocalDateTime.of(2023, 1, 23, 10, 00, 00));

  • @Test public void testFlightNo(): This method is used to test the use of proper naming convention and type (String) of the flightNo field in the student Flight class.

  • @Test public void testDestination(): This method is used to test the use of proper naming convention and type (String) of the destination field in the student Flight class.

  • @Test public void testOrigin(): This method is used to test the use of proper naming convention and type (String) of the origin field in the student Flightclass.

  • @Test public void testFlightDate(): This method is used to test the use of proper naming convention and type (LocalDateTime) of the flightDate field in the student Flightclass.

  • @Test public void testManifest(): This method is used to test the use of proper naming convention and type (LuggageManifest) of the manifest field in the student Flight class.

  • @Test public void testConstructor(): Asserts that the flight object attributes are initialized correctly with the provided parameters, i.e. String flightNo, String destination, String origin, LocalDateTime flightDate, and a new LuggageManifest object, manifest is created.

  • @Test public void testCheckInLuggage(): Asserts that the submitted checkInLuggage(Passenger p) method correctly validates a passenger's flight number to be the same as the flight object being checked into. Only when they are equal, the passenger's luggage is added to the flight's manifest using the addLuggage(...) method of the LuggageManifest class. A String representation of the outcome should be accurately returned. If the requisite flight numbers are not equal the String "Invalid flight" should be returned.

  • @Test public void testPrintLuggageManifest(): Asserts that the returned String is an accurate representation of the LuggageManifest attribute manifest in the flight object.

  • @Test public void testGetAllowedLuggage(): Tests that the method created by the student is a class method, i.e. contains the static keyword. This method also asserts that the correct number of allowed luggage is returned based on a passenger's cabin class.

  • @Test public void testToString(): Asserts that the returned String accurately represents the Flight object.

Field-Level

Fields

  • private Flight flight1: An initialized Flight field used to test the accuracy of the Flight class functionality.

Clone this wiki locally