Testing

From JetBrains/intellij-community · View interactive version

Testing is an AI agent skill from the GitHub repository JetBrains/intellij-community. Run or troubleshoot IntelliJ tests with `bt.cmd` or `tests.cmd`.

How to use this skill

Skill file

Testing Guide for IntelliJ IDEA

Quick Start

Run the tests of a module with bt first:

./community/tools/bt.cmd --module <module> --filter <FQN>

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:

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>
# 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`

cd community/platform/build-scripts/bazel
../../../../bazel.cmd test //:bazel-generator-integration-tests --test_output=all

How tests.cmd Works

tests.cmd is a cross-platform script (works on Windows/Linux/macOS)

Troubleshooting test discovery:

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>

-Dintellij.build.test.jvm.memory.options=<options>

-Dpass.<property>=<value>

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:

Bazel build fails before tests run:

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.

Additional Resources

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.