gradle Verified current stable Not installed? Build Tools

Gradle / Run Tests Matching Pattern

Run Tests Matching Pattern

Executes Gradle tests matching a specified pattern or naming convention.

$
Terminal
gradle test --tests "<pattern>"

When To Use

In large projects to selectively run tests related to specific features or issues identified in bug reports.

Pro Tip

Use double quotes around patterns to ensure proper handling of shell interpretation, particularly with special characters.

Command Builder

Tune the command before you copy it

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

Anatomy of Output

Understanding the result

> Task :test Executing Test Task with Pattern

Indicates that tests matching the specified pattern are being executed.

Running test ExampleIntegrationTest Test Case Execution

Confirms that a specific test case matched the pattern is executing.

FAILURE: Build failed due to test errors. Build Failure

Reports that one or more tests matching the pattern failed.

Power User Variants

Optimized versions

gradle test --tests "*IntegrationTests" --info

Run tests matching the given pattern with detailed output.

gradle test --tests "*Feature*Test" --rerun

Rerun all tests that match the pattern regardless of the last execution outcome.

Troubleshooting

Common pitfalls

Error: No tests found matching pattern '*IntegrationTests'.

Solution: Check the pattern syntax and ensure test methods exist that match this pattern.

FAILURE: Build failed with exception.

Solution: Review the output for details on the specific error that caused the build to fail.

Error: Test execution was interrupted.

Solution: Examine surrounding code for issues that could lead to test interruptions.

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.
<pattern>
pattern
The value supplied for pattern.
--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.