Kotlinlearncs.online LogoJava
Return to List

Test Writing: Simple Person Inheritance

Created By: Geoffrey Challen
/ Version: 2020.9.0

Create a public class called Student that inherits from a class called Person. (Do not create Person. It is already available.) Define a single public Student constructor that takes a String argument (name) and an int argument (university ID number). You should call the Person constructor and pass that String argument. (You don't need to do anything else with it.) You should also provide a public getter named getID for the student ID. Reject negative ID numbers using assert.

Test Design Challenge

You're challenge is to write tests for this problem described above.

  • Provide a public class named TestStudent with a single non-private class method named test that accepts no arguments and does not return a value.
  • If the implementation of the class described above is incorrect, your test method should throw an exception.
  • If it is correct, do not throw an exception.
  • You may want to use Java's assert method