levo

Testing an Object Oriented Application

Testing inheritance and overridden methods

  • 3 things to know
  • AS Unit 1
Start revising · £5/month

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.

Everything in your subscription

Runs, plus a mode for every other kind of session.

1Flash
2Imposter
3Fade
4Brain dump

Learn every subtopic in runs of four questions

Facts flash and fade, a wrong word hides in some of them, and a brain dump decides which questions are locked in.

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

Cram the night before, weakest topic first

A quick scan finds your weakest topics. Recall each fact you missed three times in a row.

A null is the of one.
absencepresencetype

Blank Blitz consolidates the facts

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

✓What it iscovered
~Why it happenspartly there
How long it lastsnot there yet

Explain It tests your understanding

Explain a concept in your own words and see which of its points you covered.

An error is the mistake a person made.
TrueFalse

Test It catches misconceptions

Spot the fault in a statement. The faults are the mistakes students make most often.

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.

Learn it in runs of four questions, each ending on a brain dump against the clock. Every question you lock in comes back the next day, then at longer gaps, each time just before you would forget it.

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