src/main/skills/running_gradle_tests/SKILL.md
Executes and diagnoses Gradle tests with high-precision `--tests` filtering, surgical per-test failure isolation, and full stack traces; ALWAYS use instead of `./gradlew test` for test execution, failure investigation, and post-mortem analysis. Do NOT use for general build lifecycle tasks (use `running_gradle_builds`) or dependency auditing.
npx skillsauth add rnett/gradle-mcp running_gradle_testsInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Executes tests with deep diagnostic tools to isolate and fix failures fast, ensuring maximum code quality and build reliability.
gradle tool instead of ./gradlew via shell.--tests flag for surgical test selection to minimize feedback loops.projectRoot.background: true for managed background orchestration when context isolation and non-blocking exploration are required.query_build for all test diagnostics. It provides isolated output and full stack traces that are often truncated in the main console.query_build with kind="TESTS" and query="FullTestName" to access full test output and stack traces.taskPath or captureTaskOutput to investigate specific test failures; these provide the overall task log which is often truncated and lacks per-test isolation.query_buildWhen tests fail, query_build is your most powerful diagnostic tool. It provides isolated output and full stack traces that are often truncated in the main console.
Use outcome="FAILED" to quickly see which tests failed without being overwhelmed by logs.
query_build(buildId="ID", kind="TESTS", outcome="FAILED")CRITICAL: ALWAYS use kind="TESTS" and query to see the complete stdout, stderr, and stack trace for a specific test.
query="com.example.MyTest" instead of the full FQN). If the prefix is unique, the tool will automatically select the test. If ambiguous, it will
return a list of matching names for refinement.query_build(buildId="ID", kind="TESTS", query="com.example.MyTest.myMethod")Use query with the default summary view to see all executions of a test (e.g., across different projects or iterations).
query_build(buildId="ID", kind="TESTS", query="MyTest")Use outputFile="path/to/results.txt" to write the entire result (e.g., all test outcomes, full console output) to a file. This bypasses pagination limits and is much more token-efficient for large results.
Use timeout, waitFor, or waitForTask to block until a condition is met in a background test run.
wait_build(buildId="ID", timeout=60, waitForTask=":app:test")timeout is set without a wait condition, the tool waits for the build to finish.wait_build(timeout=...).background: true ONLY for test suites that take a long time to run and you explicitly intend to perform independent research while they proceed.gradle tool uses progressive disclosure to provide concise summaries and structured results, keeping session history clean and efficient.query_build and wait_build: Use query_build to check the status of background test runs or to retrieve structured output and stack traces for failed tests.query_build(kind="FAILURES") to check for compilation or configuration issues.query option in query_build with kind="TESTS" to isolate specific failure details. For detailed diagnostic workflows, see the test_diagnostics.md reference.The --tests flag supports powerful, high-precision filtering. Use these patterns to minimize execution time and context noise.
--tests com.example.MyTest--tests com.example.MyTest.myTestMethod--tests com.example.MyTest.test* (Runs all methods starting with 'test')* and ?)--tests com.example.service.* (Runs all tests in the 'service' package)--tests *IntegrationTest (Runs all classes ending in 'IntegrationTest')--tests com.example.Test? (Matches Test1, TestA, etc.)--tests flags to run a specific selection of tests.
gradle(commandLine=["test", "--tests", "ClassA", "--tests", "ClassB"])Understanding how to target tests in a multi-project build is critical to avoid running more tests than necessary.
Providing test without a leading colon executes the test task in every project (root and all subprojects) that has one.
gradle(commandLine=["test", "--tests", "MyTest"]) -> Searches for and runs 'MyTest' in all projects.Providing a path with a leading colon targets a single specific project.
gradle(commandLine=[":test", "--tests", "MyTest"])gradle(commandLine=[":app:test", "--tests", "MyTest"])--tests) to minimize feedback loops.:app) and the test filter (e.g., com.example.MyTestClass*).gradle with commandLine including --tests.BuildId from the result.query_build(buildId=ID, kind="TESTS", outcome="FAILED") to list all failed tests.query_build(buildId=ID, kind="TESTS", query=TNAME) to see the full output and stack trace for a specific test.taskPath or captureTaskOutput for this.{
"commandLine": [":module-a:test", "--tests", "com.example.service.MyServiceTest"]
}
// Reasoning: Using an absolute task path and exact class filter for the fastest possible feedback loop.
{
"buildId": "build_20240301_130000_def456",
"outcome": "FAILED"
}
// Reasoning: Using query_build to isolate only the failures from a large test suite.
### Look up details for a specific failed test
```json
{
"buildId": "build_20240301_130000_def456",
"kind": "TESTS",
"query": "com.example.a.MyTest.shouldFail"
}
// Reasoning: Retrieving the full stack trace and isolated stdout/stderr for a specific failure.
## Troubleshooting
- **Missing environment variables**: Set `invocationArguments: { envSource: "SHELL" }` if Gradle cannot find expected env vars (e.g., `JAVA_HOME`).
## Resources
- [Test Diagnostics](./references/test_diagnostics.md)
tools
Provides authoritative guidance for ALL Gradle operations: executing builds, running tests with surgical filtering, introspecting project structure, creating modules, and diagnosing failures; ALWAYS use instead of raw shell `./gradlew` for build execution, test runs, task introspection, module creation, performance audits, and documentation research. Do NOT use for dependency graph auditing/updates (use `managing_gradle_dependencies`) or dependency/plugin/Gradle source exploration (use `exploring_dependency_sources`).
tools
Reads and searches source code across ALL scopes: external library dependencies, plugins (buildscript), and Gradle Build Tool internal source code; use whenever you need to UNDERSTAND an API — its shape, signature, parameters, overloads, or implementation — before writing any code that calls it; covers project dependencies (via project/configuration/source set scope), plugins (via `sourceSetPath=":buildscript"`), and Gradle internals (via `gradleSource: true`). Prefer this over the REPL for all API research; reading source is instantaneous and complete. Do NOT use for project source code (use grep/tilth), Gradle documentation (use `gradle_docs` via the `gradle` skill), or Maven Central discovery (use `managing_gradle_dependencies`).
development
Audits and manages Gradle dependency graphs with high-resolution update checks, transitive tree analysis, and Maven Central discovery; use for dependency auditing, finding stable updates, and resolving GAV coordinates. Do NOT use for exploring dependency source code (use `exploring_dependency_sources`) or running builds/tests (use `gradle`).
development
Executes Kotlin code interactively within the project's full JVM classpath. Use when you need to RUN code: verify runtime behavior, experiment with logic, or render Compose UI previews. Do NOT use to understand an API's shape or signature — read its source with `exploring_dependency_sources` instead.