Testing Guide for IntelliJ IDEA
Quick Start
Run the tests of a module with bt first:
./community/tools/bt.cmd --module <module> --filter <FQN>
--module: the JPS module that holds the test classes. Always use the module of the test itself. The module name is the name of the.imlfile in the test directory, without the extension.--filter: an FQN,FQN#method, or a package. A package is a dotted name whose segments start with a lower-case letter. A package value runs all the test classes in that package.
In a community checkout, the wrapper is ./tools/bt.cmd.
# Single test class (FQN)
./community/tools/bt.cmd --module intellij.platform.util.tests \
--filter com.intellij.openapi.util.io.FileUtilLightTest
# Specific test method
./community/tools/bt.cmd --module intellij.platform.util.tests \
--filter 'com.intellij.openapi.util.io.FileUtilLightTest#isAncestor'
# All test classes of a package
./community/tools/bt.cmd --module intellij.platform.util.tests \
--filter com.intellij.openapi.util.io
bt runs a module when the migrated list names it, or when a bt.json area owns its directory. The bt README gives the resolution rules.
The rules of a bt run
bt prints a short summary of the run, the digest. The rules:
- Read the whole digest. Do not filter or cut it. Do not pipe it to
grep,rg,head,tail,sed,awk,cutor a similar tool. The first line of a test run gives the status:PASS,FAIL,NO TESTS,BUILD FAILEDorINFRA. A pipe that drops the first line hides the result. The exit code gives the same status. A refusal prints no digest. It prints its message on stderr and exits 2, or 6 for a broken repository or host. - One selector and one
--filterfor each run. bt refuses a second class name, a second directory and a second--filter. To run several classes, run each class in its own call, or give their package.--filterneeds one target: one--module, one label, or a lane of one target. --moduleis the test module. Its name usually ends with.tests.- bt checks
--filterbefore the build. It changes a value with a clear meaning into the form of the runner, and anoteline names the change.pkg.Class.methodand a simpleClass#methodbecome the FQNClass#method.pkg.Outer.Inner#methodbecomespkg.Outer$Inner#method, and a nested class without a method becomes its outer class.pkg.*becomes the package. bt refuses a regex, a list and another wildcard with exit 2, before the build. - A
--filterclass is a prefix. It also runs the classes whose names start with it. AClass#methodruns only the named method. The method is the exact name, so a*in it is no wildcard. - The
envof a rule can change the filter. A target that setsJB_TEST_FILTERin theenvof its rule runs only the classes of its rule. A target that setsJB_TEST_JUNIT5_FILTERSin its rule drops a package filter. - Read the package from the
packageline of the file, not from its directory. A class or a package that does not exist givesNO TESTS. A method that does not exist givesNO TESTS, and the cause names the#methodfilter. --lane <name>alone runs the lane. Beside a selector,--laneworks only with a flow or a suite selector. These two are Air selectors.- A cached result is not a new run. For one target, the PASS line marks it
cached. For several targets, thecostline of the digest counts the cached targets. Use--no-cacheto run a passed test again. - The digest names the log of a failed run on its
logline. The logs of the last run are inout/bazel-testlogs/<package>/<target>/. A community target of the ultimate root is underexternal/community+/, and a sharded run addsshard_<n>_of_<m>/. The directory hastest.log,test.xml, andtest.outputs/logs/idea.logwhen the test writes one. The next run of the target writes over them. For a failed shard, bt keeps a copy inout/bt-runs/<run>/, and the digest names it on itskeptline. - A compile error gives
BUILD FAILEDwith the first six errors of the compiler. The digest leaves out the warnings. A label or a pattern that Bazel cannot load givesBUILD FAILEDwith the error of Bazel, such asno such package. An error in aBUILD.bazelfile can giveBUILD FAILEDwith no error. bt then writes the last lines of the Bazel output to the stderr, and these can miss the error. Then run again with--verbose.
bt options
| Option | Effect |
|--------|--------|
| --filter <value> | Runs one class, one method, or one package of the target. |
| --no-cache | Runs the tests again when Bazel has a cached result. |
| --dry-run | Prints the resolved label, the filter, and the Bazel command. Runs nothing. |
| --json | Writes one JSON object to stdout and nothing else. |
| --host <host> | Runs the working tree, local changes included, on another machine of the user through brd-host of Branch Deck. The brd-host skill (brd-host skill install) gives the rules. |
| -- --flaky_test_attempts=3 | Runs a failed test up to 3 times. tests.cmd uses -Dintellij.build.test.attempt.count=3 for this. |
| -- --test_arg=--jvm_flag=-Dkey=value | Sets a system property in the test JVM. tests.cmd uses -Dpass.key=value for this. |
| -- --test_arg=--jvm_flag=-Xmx8g | Sets the heap of the test JVM. tests.cmd uses -Dintellij.build.test.jvm.memory.options=-Xmx8g for this. |
bt gives all arguments after -- to Bazel without a change. Run ./community/tools/bt.cmd --help for all selectors and options. To attach a debugger, use tests.cmd. The section Additional JVM options shows the flags.
| Exit code | Meaning |
|-----------|---------|
| 0 | All tests passed. |
| 2 | Usage error, or bt refuses the module. |
| 3 | Tests failed. |
| 4 | Zero tests ran. |
| 5 | The build failed before the tests. |
| 6 | Infrastructure failure. |
The check record and `bt build`
A green bt run in a linked work tree, such as a Branch Deck lease, records the tree that it saw: one line in bd-checks.jsonl of the git directory. brd lease pick reads the record. A repository can set pick_requires_check in .branchdeck.toml, and then the pick refuses a lease whose tree has no green build or test. A run during which the files changed records nothing. A red run records nothing.
Check the last tree with bt, not with a raw ./bazel.cmd build. bazel.cmd gives the process to bazelisk, so it leaves no record. Commit or delete scratch files before the last check: a record of local changes counts only for a commit of the same files, and bt names those files on the stderr.
./community/tools/bt.cmd build //plugins/air/... # ./bazel.cmd build -k, one digest line, and the record
./community/tools/bt.cmd build //plugins/air/... --host studio
bt build exits 0 for a green build, 4 for BUILD EMPTY, 5 for a build failure, and 6 for an infrastructure failure. A --host run records the tree of the commit that ran on the host. The bt README gives the record format.
When bt refuses the module
bt refuses a module whose tests do not run under Bazel yet, and a module without a test target. It exits with code 2 and prints the commands to run. Run the first command. For a module whose tests do not run under Bazel, it is the tests.cmd command:
./tests.cmd --module <module> --test <pattern>
--module— the same module as for bt.--test— FQN, wildcard pattern, or FQN#methodName
# Single test class (FQN)
./tests.cmd --module intellij.cidr.compiler.custom.tests \
--test com.intellij.cidr.compiler.custom.CidrCustomCompilerReadTest
# Wildcard pattern
./tests.cmd --module intellij.goland.tests \
--test com.goide.comments.*Test
# Specific test method (wildcards cannot be used with #)
./tests.cmd --module intellij.cidr.compiler.custom.tests \
--test com.intellij.cidr.compiler.custom.CidrCustomCompilerReadTest#testSingleDefine
# Several class patterns (semicolon-separated, not with #methodName)
./tests.cmd --module intellij.platform.buildScripts.tests \
--test 'org.jetbrains.intellij.build.FileSetTest;org.jetbrains.intellij.build.ZipTest'
Simple class names like MyTest do NOT work — always use FQN or wildcard (*MyTest).
Community tests
Use community/tests.cmd for tests that belong to community-only modules:
./community/tests.cmd --module <module> --test <pattern>
API checks via Bazel
In an Ultimate checkout, run ApiCheckTest directly through its Bazel test target. For a focused check, pass one or more comma-separated module names:
./community/tools/bt.cmd //tests/ideaProjectStructure:projectStructureTests_test \
--filter com.intellij.ideaProjectStructure.api.ApiCheckTest \
-- --test_arg=--jvm_flag=-Dapi.dump.test.modules.to.check=<module>[,<module>...]
Omit --test_arg to check all modules. Do not use bazel run for this target: it streams noisy test output and does not provide Bazel's test summary.
Product layout and packaging changes
When changing ProductProperties, productImplementationModules, product content descriptors, plugin/module-set packaging, or generated product layout XML, also run:
./community/tools/bt.cmd //build/tests/smoke:all-products-packaging_test
The target pins the one class AllProductsPackagingTest and is tagged manual, so no --filter is needed, and no lane or wildcard pattern runs it.
Windows PowerShell note
When running tests.cmd from PowerShell, pass JVM -D... arguments via stop-parsing mode to avoid argument mangling:
./tests.cmd --% --module <module> --test com.example.MyTest -Dintellij.build.test.attempt.count=3
Without --%, PowerShell can alter -D... arguments before they reach tests.cmd, which may lead to errors like Could not find or load main class ....
Separate Bazel Modules
Some parts of the repository are standalone Bazel modules and must not use tests.cmd or community/tests.cmd. The tests of a module that matches a pattern in the migrated list run only under Bazel. The migrated list is community/build/bazel-migrated-test-modules.txt, or build/bazel-migrated-test-modules.txt in a community checkout. tests.cmd refuses such a module with an error that names the pattern. Run the module with bt:
./community/tools/bt.cmd --module <module> --filter <FQN>
When you have the Bazel label of the target, ./community/tools/bt.cmd <label> --filter <FQN> runs the same target.
`community/platform/build-scripts/bazel`
- This directory is a separate Bazel module.
- Tests in this module must be run via Bazel from that directory.
- Use the command documented in
community/platform/build-scripts/bazel/README.md:
cd community/platform/build-scripts/bazel
../../../../bazel.cmd test //:bazel-generator-integration-tests --test_output=all
- If a request touches files under
community/platform/build-scripts/bazel, prefer that module-local../../../../bazel.cmd testflow for verification.
How tests.cmd Works
tests.cmd is a cross-platform script (works on Windows/Linux/macOS)
Troubleshooting test discovery:
- Bazel incremental compilation works correctly — remote caches do NOT cause staleness, don't waste time on
./bazel.cmd clean
tests.cmd Parameters
./tests.cmd --help prints the usage. --debug debugs the JVM process of the build scripts.
Additional JVM options
Extra -D... arguments are passed through as JVM flags to org.jetbrains.intellij.build.TestingOptions:
-Dintellij.build.test.attempt.count=<n>
- The number of attempts. From the second attempt, only the failed tests run again.
- Default: 1 (no retries)
- Use 3 for flaky tests
-Dintellij.build.test.jvm.memory.options=<options>
- Custom JVM memory options for the test process
- Example:
-Xmx8gfor 8GB heap
-Dpass.<property>=<value>
- Pass arbitrary system properties to the test JVM
- The
pass.prefix is stripped, so-Dpass.my.flag=truebecomes-Dmy.flag=truein the test JVM
Debugging: -Dintellij.build.test.debug.enabled=true -Dintellij.build.test.debug.port=5005 -Dintellij.build.test.debug.suspend=true — attach IDE debugger to port 5005.
Troubleshooting
Tests fail with OutOfMemoryError:
- Increase heap size:
-Dintellij.build.test.jvm.memory.options=-Xmx8g
Bazel build fails before tests run:
- Check module dependencies in
.imlfile - Consult module-dependencies
Read references/testing-internals.md when you debug the test discovery or the runner of bt.cmd or tests.cmd. Examples are a test that is not found, the wrong tests that run, a pattern that matches no class, and the bucketing.
Writing Tests
Always read Writing Tests before you write a new test.