Testing Tip: Run Test Method from Abstract Test Class

Sometimes you have an abstract test class with test methods where the inheritors set up different environment. As it is impossible to run an abstract class you had to enumerate inheritors manually, choose corresponding methods and run these methods one by one.

Now (since IntelliJ IDEA 11.1) it is possible to run tests right from the abstract base class and simply choose inheritors from the popup.

This works for JUnit and for TestNG tests.

Comments below can no longer be edited.

5 Responses to Testing Tip: Run Test Method from Abstract Test Class

  1. Avatar

    Jan Jordanow says:

    June 13, 2013

    is there some configuration? cause this ‘popup with inheritors ‘ doesn’t pop up each time. Is it a bug or feature?

  2. Avatar

    Anna Kozlova says:

    June 17, 2013

    Hi Jan,

    Sounds more like a bug. Could you please file more details? When it doesn’t appear? Thanks

  3. Avatar

    Isaac Aggrey says:

    May 19, 2015

    The popup doesn’t seem to appear if you have a run configuration for the abstract base class instead of the concrete class. In order to reproduce, all you have to do is change the Class in the run configuration for the test to the abstract base class*, but once I deleted that configuration it shows the popup again.

    *which of course won’t work when you run the test due to it failing to instantiate, but you may still end up in this state if you don’t know what you’re doing or have an old configuration after refactoring

  4. Avatar

    Arun Kottayil says:

    December 22, 2016

    @Isaac Aggrey, Thanks , saved my day.

  5. Avatar

    Blair Stewart says:

    July 24, 2018

    @Isaac Aggrey, Thank you. Having the same problem in Intellij 2018.1.6, you saved the say again.

Discover more