Test cases for abstract class in Java

Re: Test cases for abstract class in Java

by Richard Lobb -
Number of replies: 0
I don't teach Java so have no experience to report on, but since no-one else has responded ...

I'm guessing you would want to use the Write a class question type (or perhaps a derivative of it, customised for your own needs). Then write a series of tests along the following lines:
  1. Try to instantiate the class (in a try ... catch construct) and expect to catch whatever exception Java throws when you instantiate an abstract class.
  2. Declare a subclass that does not implement the declared abstract methods. Try to instantiate it. Again expect to catch the appropriate exceptions.
  3. Declare a subclass with all the required extra functionality. Instantiate it. Test all the functionality that the abstract class is meant to provide.
  4. If you're very keen, you could try a series of variants of (3), each lacking an implementation of one of the abstract methods. Expect to get exceptions as in 2.