Testing Integration
How Gradle runs tests: the Test task with its forking and logging, JVM test suites, framework wiring, filtering and reports, and coverage. Interviewers ask because every real build's CI story runs straight through these settings.
on this pageshowhide
explore
- The Test Task25 questions
- Test Engine Activation5 questions
- Parallel Test Execution5 questions
- Test JVM Forking & Args5 questions
- System Properties & Environment5 questions
- Failure Handling & Logging5 questions
- JVM Test Suites25 questions
- Test Suites DSL Basics5 questions
- Declaring an integrationTest Suite5 questions
- Suite Dependencies & Production Access5 questions
- Suite Targets & Lifecycle5 questions
- Test JVM and Toolchain in Suites5 questions
- Framework Wiring20 questions
- JUnit 5 / Jupiter Setup5 questions
- JUnit 4 Vintage Engine5 questions
- TestNG Wiring5 questions
- Version Alignment via BOM5 questions
- Selection & Reporting20 questions
- --tests Filter5 questions
- Filter Block & Tags5 questions
- HTML & JUnit-XML Reports5 questions
- Test Report Aggregation5 questions
- Coverage & Plugin Testing21 questions
- JaCoCo Report5 questions
- Coverage Verification Rules5 questions
- JaCoCo Aggregation6 questions
- TestKit GradleRunner5 questions
questions
111 · 5 sectionsHow do you pass a system property from a Gradle build into your test JVM, and how do you read it inside the test code?
basics
~10 sConfigure the Test task with systemProperty("key", "value") (or test { systemProperty ... }). In the test, read it with System.getProperty("key"). It is set on the forked test JVM, not the build JVM.
What does the `ignoreFailures` property on Gradle's `Test` task do, and why might you set it?
basics
~20 sSetting test.ignoreFailures = true tells Gradle not to fail the build when tests fail. The test task still runs all tests and reports results, but a failing test no longer marks the build as failed.
How do you control the heap size of the JVM that runs your tests in Gradle, and where do you configure it?
basics
~10 sTests run in a separate forked JVM. On the test task set minHeapSize and maxHeapSize (e.g. "256m" / "1g"). These map to the forked JVM's -Xms and -Xmx, not the Gradle daemon's heap.
What does the `maxParallelForks` property on Gradle's `Test` task do, and how do you set it?
basics
~10 smaxParallelForks sets how many test JVM processes Gradle runs at once for a single Test task. Set it in the test task config, e.g. tasks.test { maxParallelForks = 4 }. Default is 1.
How do you tell Gradle to run your tests with JUnit 5 (Jupiter) instead of JUnit 4? What single line is involved and where does it go?
basics
~10 sCall useJUnitPlatform() on the Test task in build.gradle.kts, e.g. tasks.test { useJUnitPlatform() }. Without it Gradle defaults to the JUnit 4 (Vintage) runner and won't discover Jupiter tests.
Inside a JVM test suite's dependencies block, how do you give an integrationTest suite access to your project's own main/production classes?
basics
~10 sAdd implementation(project()) inside the suite's dependencies { } block. The bare project() call refers to the current project, so the suite compiles and runs against main classes.
What is the `testing { suites { } }` block in Gradle, and which plugin provides it?
basics
~10 sIt is a DSL from the built-in jvm-test-suite plugin for declaring test suites (groups of tests). It is applied automatically by the java plugin and exposes a default suite named test.
How do you declare a separate integrationTest test suite in a Gradle build using the JVM Test Suite plugin, and what does that one declaration give you for free?
basics
~10 sInside the testing.suites block, register a suite with val integrationTest by registering(JvmTestSuite::class). Gradle then auto-creates the integrationTest source set, the integrationTest task, and its dependency configurations — no manual source-set wiring needed.
Inside a JVM test suite, how do you configure the underlying Test task (for example to call useJUnitPlatform()) using the targets DSL?
basics
~10 sGo through the suite's targets: targets { all { testTask.configure { useJUnitPlatform() } } }. Each target exposes a testTask provider you configure, instead of touching the top-level test task directly.
A teammate's custom integrationTest suite fails to compile with 'cannot find symbol' for classes from a library that the unit tests use fine. What's the likely cause and fix, given how suite dependencies work?
basics
~20 sCustom suites don't inherit testImplementation. The library was declared only for the test suite, so the integration suite never saw it. Fix: declare it in the integrationTest suite's dependencies { }, or make integrationTestImplementation extend testImplementation.
What is the JUnit BOM and why would you use `testImplementation(platform("org.junit:junit-bom:..."))` in a Gradle build instead of pinning each JUnit artifact's version individually?
basics
~20 sThe JUnit BOM is a Bill of Materials that declares one consistent version for all JUnit modules (Jupiter, Platform, Vintage). Importing it with platform(...) lets you list JUnit dependencies without versions, so they all align.
How do you tell Gradle's Test task to run JUnit 5 (Jupiter) tests instead of the default JUnit 4 runner?
basics
~10 sCall useJUnitPlatform() on the test task. By default Gradle uses the JUnit 4 runner, so you must opt into the JUnit Platform for Jupiter tests to be detected and executed.
A team adds junit-jupiter-api and calls useJUnitPlatform(), but the build reports zero tests run. What is the most likely cause and the fix?
basics
~10 sThey added only the API, not the engine. Without junit-jupiter-engine on testRuntimeOnly the Platform has nothing to discover the tests. Add the engine (or the junit-jupiter aggregator) and the tests run.
How do you configure a Gradle project to run tests with TestNG instead of the default JUnit?
basics
~10 sAdd the TestNG dependency to testImplementation, then call useTestNG() inside the test task. Without useTestNG(), Gradle assumes JUnit and won't detect @Test annotations from TestNG.
What is the JUnit Vintage engine, and how do you enable it in a Gradle build so that legacy JUnit 4 tests run on the JUnit Platform?
basics
~10 sVintage is a JUnit Platform TestEngine that runs JUnit 4 tests. Add testRuntimeOnly('org.junit.vintage:junit-vintage-engine') and call useJUnitPlatform() in the test task so Gradle discovers and runs them.
What is the `test-report-aggregation` plugin in Gradle and what problem does it solve in a multi-project build?
basics
~10 sIt's a core Gradle plugin that merges the test results of multiple subprojects into a single combined HTML report, so you don't have to open each subproject's report separately.
What does the `filter {}` block inside a `Test` task do, and how do `includeTestsMatching` and `excludeTestsMatching` work?
basics
~10 sThe filter {} block on a Test task selects which tests run by pattern. includeTestsMatching('*Foo*') keeps only matching tests; excludeTestsMatching drops matching ones. Patterns match fully-qualified class/method names with * wildcards.
After running `./gradlew test`, where does Gradle put the human-readable test report and the machine-readable results, and which one do you open in a browser?
basics
~10 sGradle writes an HTML report under build/reports/tests/test/ (open index.html in a browser) and machine-readable JUnit-XML under build/test-results/test/. You open the HTML in a browser.
How do you run a single test class or a single test method from the command line with Gradle?
basics
~10 sUse the --tests flag on the test task: ./gradlew test --tests 'com.example.MyTest' runs one class, and ./gradlew test --tests 'com.example.MyTest.myMethod' runs one method.
How do you set up test report aggregation across several subprojects? Walk through applying the plugin and declaring what gets aggregated.
basics
~10 sApply test-report-aggregation on an aggregating project, add each subproject via the testReportAggregation dependency configuration, then run testAggregateTestReport to get one merged HTML report.
How do you enable JaCoCo code-coverage reporting in a Gradle build, and what does applying the jacoco plugin give you?
basics
~10 sAdd jacoco to the plugins {} block. Gradle then adds a jacocoTestReport task and a jacoco {} extension, and instruments your tests so coverage data is collected when you run test.
What is Gradle TestKit's GradleRunner, and how do you use it to functionally test a Gradle plugin?
basics
~20 sGradleRunner is the TestKit entry point that runs a real Gradle build against a temporary project directory. You create it, point it at a project dir, pass arguments, and call build() to execute and inspect the result.
What does the jacocoTestCoverageVerification task do in a Gradle build, and how do you make it fail the build when coverage drops below a threshold?
basics
~10 sIt's a JaCoCo plugin task that checks coverage against rules you define in violationRules. If coverage is below the configured minimum, the task fails, which fails the build.
Your testCodeCoverageReport runs successfully but the merged report shows 0% or is missing whole modules. How do you debug it?
basics
~10 sCheck that each module applies jacoco/jvm-test-suite (so it exposes coverage variants), that its tests actually ran and produced .exec data, that it's reachable via jacocoAggregation, and that the right testSuiteName is aggregated.
What does the jacoco-report-aggregation plugin do, and why would you use it in a multi-project Gradle build?
basics
~10 sIt merges JaCoCo coverage data from several subprojects into one combined HTML/XML report, so you see total coverage across the whole multi-project build instead of per-module reports.