gradle Verified current stable Not installed? Build Tools

Gradle / Run Specific Test Class

Run Specific Test Class

Executes a specific test class in a Gradle project.

$
Terminal
gradle test --tests <class_name>

When To Use

When isolating tests for a particular feature or fix to expedite the debugging process.

Pro Tip

Combine with the --info flag to gain detailed insights regarding test execution and results.

Command Builder

Tune the command before you copy it

Back to syntax
$
Generated Command
gradle test --tests <class_name>

Anatomy of Output

Understanding the result

> Task :test Executing Test Task

Indicates that the test task for the specified class is being run.

Running YourTestClass Test Class Execution

Confirms the specific test class is executing.

OK Test Outcome

Indicates successful execution of the specified test class.

Power User Variants

Optimized versions

gradle test --tests YourTestClass --info

Run the specified test class with detailed output.

gradle test --tests YourTestClass --rerun

Rerun tests in specified class regardless of last execution outcomes.

Troubleshooting

Common pitfalls

Error: Test class 'YourTestClass' not found.

Solution: Ensure the class name is correct and follows proper naming conventions.

FAILURE: Build failed because of test errors.

Solution: Review the test methods in the specified class for failures.

Error: No tests found in class 'YourTestClass'.

Solution: Ensure the class contains methods annotated with @Test.

Command Breakdown

What each part is doing

gradle
Base Command
The executable that performs this operation. Here it runs Gradle before the shell applies any redirect operators.
<class_name>
class name
The value supplied for class name.
--tests
Command Option
Tool-specific option used by this command invocation.

Alternative Approaches

Comparable commands in other tools

Alternative build tools tools for the same job.