Partner – Moderne – NPI EA (cat=Spring Boot)
announcement - icon

Refactor Java code safely — and automatically — with OpenRewrite.

Refactoring big codebases by hand is slow, risky, and easy to put off. That’s where OpenRewrite comes in. The open-source framework for large-scale, automated code transformations helps teams modernize safely and consistently.

Each month, the creators and maintainers of OpenRewrite at Moderne run live, hands-on training sessions — one for newcomers and one for experienced users. You’ll see how recipes work, how to apply them across projects, and how to modernize code with confidence.

Join the next session, bring your questions, and learn how to automate the kind of work that usually eats your sprint time.

Course – Black Friday 2026 – NPI EA – main – before_post_content
announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 4th December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW

Course – Black Friday 2026 – NPI – main – before_post_content
announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 4th December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW

1. Overview

This tutorial will discuss possible solutions to skip running tests from base test classes in JUnit 4. For purposes of this tutorial, a base class has only helper methods, while children classes will extend it and run actual tests.

2. Bypass Base Test Class

Let’s assume we have a BaseUnitTest class with some helper methods:

public class BaseUnitTest {
    public void helperMethod() {
        // ...
    }
}

Now, let’s extend it with a class that has tests:

public class ExtendedBaseUnitTest extends BaseUnitTest {
    @Test
    public void whenDoTest_thenAssert() {
        // ...        
    }
}

If we run tests, either with an IDE or a Maven build, we might get an error telling us about no runnable test methods in BaseUnitTest. We don’t want to run tests in this class, so we’re looking for a way to avoid this error.

We’ll take a look at three different possibilities. If running tests with an IDE, we might get different results, depending on our IDE’s plugin and how we configure it to run JUnit tests.

2.1. Rename Class

We can rename our class to a name that the build convention will exclude from running as a test. For example, if we’re using Maven, we can check the defaults of the Maven Surefire Plugin.

We could change the name from BaseUnitTest to BaseUnitTestHelper or similar:

public class BaseUnitTestHelper {
    public void helperMethod() {
        // ...
    }
}

2.2. Ignore

A second option would be to disable tests temporarily using the JUnit @Ignore annotation. We can add it at the class level to disable all tests in a class:

@Ignore("Class not ready for tests")
public class IgnoreClassUnitTest {
    @Test
    public void whenDoTest_thenAssert() {
        // ...
    }
}

Likewise, we can add it at the method level, in case we still need to run other tests within the class but only exclude one or a few:

public class IgnoreMethodTest {
    @Ignore("This method not ready yet")
    @Test
    public void whenMethodIsIgnored_thenTestsDoNotRun() {
        // ...
    }
}

If running with Maven, we will see output like:

Tests run: 1, Failures: 0, Errors: 0, Skipped: 1, Time elapsed: 0.041 s - in com.baeldung.IgnoreMethodTest

The @Disabled annotation replaces @Ignore since JUnit 5.

2.3. Make the Base Class abstract

Possibly the best approach is to make a base test class abstract. Abstraction will require a concrete class to extend it. That’s why JUnit will not consider it a test instance in any case.

Let’s make our BaseUnitTest class abstract:

public abstract class BaseUnitTest {
    public void helperMethod() {
        // ...
    }
}

3. Conclusion

In this article, we’ve seen some examples of excluding a base test class from running tests in JUnit 4. The best approach is to create abstract classes.

JUnit’s @Ignore annotation is also widely used but is considered a bad practice. By ignoring tests, we might forget about them and the reason for their ignoring.

The code backing this article is available on GitHub. Once you're logged in as a Baeldung Pro Member, start learning and coding on the project.
Partner – Moderne – NPI EA (tag=Refactoring)
announcement - icon

Modern Java teams move fast — but codebases don’t always keep up. Frameworks change, dependencies drift, and tech debt builds until it starts to drag on delivery. OpenRewrite was built to fix that: an open-source refactoring engine that automates repetitive code changes while keeping developer intent intact.

The monthly training series, led by the creators and maintainers of OpenRewrite at Moderne, walks through real-world migrations and modernization patterns. Whether you’re new to recipes or ready to write your own, you’ll learn practical ways to refactor safely and at scale.

If you’ve ever wished refactoring felt as natural — and as fast — as writing code, this is a good place to start.

Course – Black Friday 2026 – NPI EA – main – after_post_content

announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 4th December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW

Course – Black Friday 2026 – NPI – main – after_post_content

announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 4th December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW