gradle-test
TLDR
Run all tests
Run tests with detailed output
Run a specific test class
Run tests matching a pattern
Rerun tests even if up-to-date
SYNOPSIS
gradle-test [options] [additional-tasks]
PARAMETERS
--help
Display help for test task
--version
Print Gradle version
-p, --project-dir <dir>
Set project directory
--continue
Continue tests after failure
--tests <pattern>
Run specific tests by name pattern
--test-pattern <pattern>
Filter tests by regex pattern
--dry-run
Print tests that would run without executing
--debug-jvm
Enable JVM debugging for tests
-Dtest.property=value
Pass system properties to tests
--max-parallel-forks <N>
Set max parallel test forks
-Pprop=value
Set Gradle project property
--rerun-tasks
Force re-run of all tests
-x test
Skip the test task entirely
DESCRIPTION
The gradle-test command executes the Gradle test task, a core feature of the Gradle build automation tool designed for Java, Kotlin, and other JVM languages. It compiles both production and test source code, then runs unit tests using frameworks like JUnit, TestNG, or Spock.
By default, it processes all tests in the src/test directories, producing detailed HTML reports in build/reports/tests/test/index.html. Tests run in parallel for speed, with configurable max workers via maxParallelForks. Failure halts execution unless --continue is used, allowing full suite completion.
It supports filtering via --tests or --test-pattern, dry runs with --dry-run, and debugging with --debug. Integration with CI/CD tools like Jenkins or GitHub Actions is seamless through report artifacts. Gradle caches test results for faster re-runs unless invalidated by --rerun-tasks.
Ideal for large-scale projects, it handles incremental compilation and dependency resolution efficiently, ensuring reproducible builds.
CAVEATS
Requires Gradle installed and a valid build.gradle file with test task defined. Needs JDK 8+. Test reports may consume significant disk space in large projects. Daemon recommended for performance but can leak memory if not stopped.
EXAMPLES
gradle-test
gradle-test --tests '*MyTest'
gradle-test --continue -Penv=prod
REPORTS LOCATION
HTML: build/reports/tests/test/index.html
XML: build/test-results
HISTORY
Gradle introduced in 2007 by Hans Dockter; test task core since v0.1. Evolved with parallel execution in v1.12 (2013), TestNG support early on, and JUnit 5 integration in v4.6 (2017). gradle-test wrappers emerged in CI tools circa 2015 for simplified invocation.


