Kotlinlearncs.online LogoJava
Return to List

Test Writing: Simple Dog Inheritance

Created By: Geoffrey Challen
/ Version: 2021.3.0

Create a public class named Dog. Dog should inherit from the Canine class shown below:

(You do not need to define Canine.)

You should provide a public constructor that allows the age of the Dog to be set (as a double) when it is created. assert that the passed age is not negative. You should not expose the age and do not need to provide either a setter or a getter for it. You should pass the kind "dog" to the Canine constructor when creating a Dog.

Dog should override toString and return a String in the following format: "This dog is (age) years old".

Test Design Challenge

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

  • Provide a public class named TestDog 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