REW

How Do I Run All Test Classes In Eclipse?

Published Aug 29, 2025 3 min read
On this page

You can run all test classes in Eclipse by right-clicking on your project's test folder, a specific package, or the project root itself and choosing Run As > JUnit Test. For projects using build tools like Maven or Gradle, you can also trigger the tests via the Eclipse-integrated build tool menu.

Method 1: Running tests via the Package Explorer

This is the most direct and common way to execute a full test suite. The scope of the tests run depends on the folder you select.

To run all tests in the entire project:

  1. Navigate to the Package Explorer or Project Explorer view.
  2. Right-click on the project's main folder (the root folder).
  3. Select Run As > JUnit Test.
  4. This action automatically detects all JUnit test classes and executes them. The results will be displayed in the dedicated JUnit view.

To run all tests within a specific package:

  1. In the Package Explorer, locate the package containing the test classes you want to run.
  2. Right-click on the package folder.
  3. Choose Run As > JUnit Test.
  4. This will execute all test classes directly within that package. However, it will not run tests in any sub-packages.

To run all tests within a source folder (like src/test/java):

  1. Expand your project and find the source folder that contains your test packages, often named src/test/java.
  2. Right-click on the source folder.
  3. Select Run As > JUnit Test.
  4. This will execute all tests within that folder and all of its sub-packages.

Method 2: Running tests with a build tool (Maven or Gradle)

For projects using build automation tools, it's often best to run tests through the build tool's interface in Eclipse. This ensures consistency with how tests are run in your Continuous Integration (CI) pipeline.

Using Maven:

  1. In the Package Explorer, right-click on your project's pom.xml file.
  2. Select Run As > Maven Test.
  3. This command executes the test phase of your Maven build, which runs all test classes by default. The output is displayed in the Eclipse console view.

Using Gradle:

  1. Ensure you have the Buildship plugin installed, which provides Gradle integration in Eclipse.
  2. Right-click on your project in the Package Explorer.
  3. Select Run As > Gradle Test.
  4. This executes the Gradle test task. The results appear in the Console view and the Gradle Executions view.

Method 3: Creating a Test Suite

For older projects using JUnit 3 or JUnit 4, you can create a dedicated "suite" class to aggregate multiple test classes or packages. This is useful for grouping tests into logical sets.

For JUnit 4:

  1. Create a new class and add the @RunWith(Suite.class) and @Suite.SuiteClasses annotations.
  2. List all the test classes you want to include inside the SuiteClasses annotation.

Example:

import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
import com.example.tests.MyFirstTest;
import com.example.tests.MySecondTest;
@RunWith(Suite.class)
@SuiteClasses({MyFirstTest.class, MySecondTest.class})
public class MyTestSuites {
    // This is an empty class that acts as a container for the test suite.
}

Use code with caution.

  1. To run the suite, right-click on the MyTestSuites.java file and select Run As > JUnit Test.

For JUnit 5:

JUnit 5 has a more flexible approach to test suites using the @Suite and @SelectPackages or @SelectClasses annotations.

Example (using packages):

import org.junit.platform.suite.api.SelectPackages;
import org.junit.platform.suite.api.Suite;
@Suite
@SelectPackages({"com.example.tests", "com.example.other.tests"})
public class AllTestSuites {
}

Use code with caution.

  1. Right-click the suite class and select Run As > JUnit Test to run it.

Method 4: Using Run Configurations

You can also use Run Configurations for more tailored and repeatable test executions.

  1. Go to Run > Run Configurations...
  2. Create a new JUnit configuration.
  3. Specify your project and choose to run all tests in a project, package, or source folder, a single class, or a suite.
  4. Configure other settings and click Run. These configurations can be easily re-used.
Enjoyed this article? Share it with a friend.