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.

0 0 vote
Article Rating

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
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments