Explore Courses Blog Tutorials Interview Questions
0 votes
in Java by (2.6k points)

I was wondering how to unit test abstract classes, and classes that extend abstract classes.

Should I test the abstract class by extending it, stubbing out the abstract methods, and then test all the concrete methods? Then only test the methods I override and test the abstract methods in the unit tests for objects that extend my abstract class?

Should I have an abstract test case that can be used to test the methods of the abstract class, and extend this class in my test case for objects that extend the abstract class?

Note that my abstract class has some concrete methods.

1 Answer

0 votes
by (46k points)
You need to write a Mock object and apply them just for testing. They normally are very very very least (inherit from the intellectual class) and not more. Then, in your Unit Test, you can execute the abstract method you need to test.

You should test the intellectual classes that include some logic like all other classes you have.

Related questions

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers


94k users

Browse Categories