Test cases for abstract class in Java

Test cases for abstract class in Java

by wael hadi -
Number of replies: 1

Hello everyone,

I hope you're all doing well. I'm currently working on designing test cases for an abstract class in Java, and I would appreciate some input from the community.

Could you please share some examples of test cases that are commonly used for testing abstract classes in Java?

Your insights and suggestions would be incredibly valuable to me. Thank you for taking the time to help out.


In reply to wael hadi

Re: Test cases for abstract class in Java

by Richard Lobb -
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.