skip to content

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 pageshow

explore

questions

111 · 5 sections

How do you pass a system property from a Gradle build into your test JVM, and how do you read it inside the test code?

level: juniorimportance: must knowfreq 70%
basics
~10 s

Configure 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.

open as a page

What does the `ignoreFailures` property on Gradle's `Test` task do, and why might you set it?

level: juniorimportance: must knowfreq 55%
basics
~20 s

Setting 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.

open as a page

How do you control the heap size of the JVM that runs your tests in Gradle, and where do you configure it?

level: juniorimportance: must knowfreq 55%
basics
~10 s

Tests 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.

open as a page

What does the `maxParallelForks` property on Gradle's `Test` task do, and how do you set it?

level: juniorimportance: must knowfreq 70%
basics
~10 s

maxParallelForks 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.

open as a page

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?

level: juniorimportance: must knowfreq 80%
basics
~10 s

Call 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.

open as a page

Inside a JVM test suite's dependencies block, how do you give an integrationTest suite access to your project's own main/production classes?

level: juniorimportance: must knowfreq 60%
basics
~10 s

Add 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.

open as a page

What is the `testing { suites { } }` block in Gradle, and which plugin provides it?

level: juniorimportance: must knowfreq 55%
basics
~10 s

It 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.

open as a page

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?

level: juniorimportance: must knowfreq 70%
basics
~10 s

Inside 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.

open as a page

Inside a JVM test suite, how do you configure the underlying Test task (for example to call useJUnitPlatform()) using the targets DSL?

level: juniorimportance: must knowfreq 55%
basics
~10 s

Go 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.

open as a page

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?

level: middleimportance: must knowfreq 40%
basics
~20 s

Custom 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.

open as a page

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?

level: juniorimportance: must knowfreq 60%
basics
~20 s

The 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.

open as a page

How do you tell Gradle's Test task to run JUnit 5 (Jupiter) tests instead of the default JUnit 4 runner?

level: juniorimportance: must knowfreq 78%
basics
~10 s

Call 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.

open as a page

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?

level: juniorimportance: must knowfreq 55%
basics
~10 s

They 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.

open as a page

How do you configure a Gradle project to run tests with TestNG instead of the default JUnit?

level: juniorimportance: must knowfreq 55%
basics
~10 s

Add 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.

open as a page

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?

level: juniorimportance: must knowfreq 60%
basics
~10 s

Vintage 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.

open as a page

What is the `test-report-aggregation` plugin in Gradle and what problem does it solve in a multi-project build?

level: juniorimportance: must knowfreq 55%
basics
~10 s

It'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.

open as a page

What does the `filter {}` block inside a `Test` task do, and how do `includeTestsMatching` and `excludeTestsMatching` work?

level: juniorimportance: must knowfreq 55%
basics
~10 s

The 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.

open as a page

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?

level: juniorimportance: must knowfreq 62%
basics
~10 s

Gradle 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.

open as a page

How do you run a single test class or a single test method from the command line with Gradle?

level: juniorimportance: must knowfreq 70%
basics
~10 s

Use 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.

open as a page

How do you set up test report aggregation across several subprojects? Walk through applying the plugin and declaring what gets aggregated.

level: middleimportance: must knowfreq 50%
basics
~10 s

Apply test-report-aggregation on an aggregating project, add each subproject via the testReportAggregation dependency configuration, then run testAggregateTestReport to get one merged HTML report.

open as a page

How do you enable JaCoCo code-coverage reporting in a Gradle build, and what does applying the jacoco plugin give you?

level: juniorimportance: must knowfreq 70%
basics
~10 s

Add 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.

open as a page

What is Gradle TestKit's GradleRunner, and how do you use it to functionally test a Gradle plugin?

level: juniorimportance: must knowfreq 55%
basics
~20 s

GradleRunner 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.

open as a page

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?

level: juniorimportance: must knowfreq 60%
basics
~10 s

It'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.

open as a page

Your testCodeCoverageReport runs successfully but the merged report shows 0% or is missing whole modules. How do you debug it?

level: middleimportance: must knowfreq 40%
basics
~10 s

Check 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.

open as a page

What does the jacoco-report-aggregation plugin do, and why would you use it in a multi-project Gradle build?

level: middleimportance: must knowfreq 55%
basics
~10 s

It 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.

open as a page