levo

Testing an Object Oriented Application

Testing inheritance and overridden methods

  • 3 things to know
  • AS Unit 1

Overview

Confirming an inherited method still behaves in the subclass, that an overridden method is the one that actually runs, and that a call through a base-class reference reaches the right version.

What you need to know

Answer each one before you reveal it.

Your recallNot started
Key term

Why does a deep hierarchy make testing harder?

Key term

Why must a subclass be tested even though the base class has already passed its tests?

Key term

What is tested about an inherited method the subclass does not change?

Questions from this subtopic

Each one with the model answer underneath.

  1. 1

    Why must a subclass be tested even though the base class has already passed its tests?

    Model answer

    A subclass adds attributes and may change behaviour, so the inherited methods now run in a different context and may no longer produce the right result.

  2. 2

    What is tested about an inherited method the subclass does not change?

    Model answer

    The test confirms the method still gives correct results for objects of the subclass, since the subclass's own attributes and constructor may leave the object in a state the base class never encountered.

  3. 3

    What must a test of an overridden method establish?

    Model answer

    The test must show that the subclass version is the one that runs and that it gives the result the subclass requires, rather than the result the base class would have produced.

  4. 4

    Employee.calculatePay returns hours multiplied by rate, and Manager overrides it to add a bonus of 500. Which two tests are needed?

    Model answer

    One test creates an Employee and confirms the pay equals the hours multiplied by the rate, and the other creates a Manager with the same hours and rate and confirms the pay is 500 greater.

  5. 5

    How is polymorphic behaviour tested?

    Model answer

    A test places objects of several subclasses in an array of the base type, calls the same method on each element, and confirms that every object produced the result belonging to its own class.

  6. 6

    Why is a test made through a base-class reference important?

    Model answer

    The finished application will often hold subclass objects in base-type variables, so testing that way proves the correct version is chosen while the program runs.

Other ways to work this

The same content, four other ways.

What is inside Levo

Six ways to work the same material.

1Closed book
2Open book
3Closed book

The 3-step method, run for you

Answer cold, learn it, then prove it stuck. Levo tracks the jump between your first attempt and your last.

Software and the Development Environment
Defining Data: Types, Variables and Classes
Program Control Structures
Objects, Classes and Data Structures

Cram a whole paper in one sitting

Sort every topic into what you know and what you do not, then drill only the weak ones.

A null is the of one.
absencepresencetype

Blank Blitz makes facts automatic

Rapid timed gap-fills on the terms and numbers you need to recall without thinking.

AA null means no value has been recorded.
BZero and an empty string are values.
CA null is the absence of a value.

Build It gets the exam shape right

Assemble a full-mark answer from its marking points, in the order an examiner wants them.

An error is the mistake a person made.
TrueFalse

Test It catches misconceptions

Spot the fault in a statement. The traps are the mistakes students actually make.

721941163128510

Brain Breaks between sessions

Short focus games to reset attention, so the next set lands better than the last.

Every question in Testing an Object Oriented Application, on a schedule.

Attempt a question from memory, write the correct version, then attempt it again. Levo records the jump between your first attempt and your last, and brings each question back on the day you are due to forget it.

Or £46 a year, about £3.83 a month. Cancel anytime.