Kotlinlearncs.online LogoJava
Return to List

Test Writing: Simple Dog Inheritance

Created By: Geoffrey Challen
/ Version: 2021.3.0

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

(You do not need to define Canine.)

You should provide a primary constructor that allows the age of the Dog to be set (as a double) when it is created. require that the passed age is not negative. Your property storing the age should not be publicly visible. 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 Kotlin's assert or check methods