Testing abstract classes without creating child object

testing abstract class
Share on facebook
Share on twitter
Share on linkedin

Abstract classes can contain concrete methods which should be tested. One way to do it would be to create child class of the abstract class and test that one.

Let’s imagine that we have abstract class Person

While we are testing this class, usually we would create for example class Doctor which extends Person

so test would look like:

However there’s more elegant way to test abstract class without creating unnecessary child object:

More info about mocking abstract classes and traits can be found here.

Subscribe to our newsletter

Be first to read new helpful post

Share this post with your friends

Share on linkedin
Share on xing
Share on twitter
Share on facebook

Communian – GO LIVE

In one of our previous blog posts we have announced Communian – an event platform for local communities, that will allow you to find interesting

Leave a Reply

avatar
  Subscribe  
Notify of