дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-03 16:51:16 +02:00
The test tree toolbar of every test runner (Jest and Vitest keep their watch mode) gets Rerun Automatically, with More Actions > Set AutoTest Delay (1-10 s, 3 by default). A delay after the last editor save of a project file, every tab with the toggle on runs its tests again in place without taking focus. Nothing runs while a saved file has a syntax error; a running test, a before launch build or a debug session of a configuration without parallel runs is not stopped but waited for; an automatic run saves no other file. The toggle lasts as long as the tab. Part of #4968 Co-authored-by: wildcatDownstairs <[email protected]>
91 рядки
7.7 KiB
Plaintext
91 рядки
7.7 KiB
Plaintext
---
|
||
title: "Testing"
|
||
description: "Run tests from the gutter, read results in the test tree, rerun failed tests and jump between code and tests."
|
||
---
|
||
|
||
OpenIDEA runs tests with the project's own test tool (Cargo, Jest, pytest, Maven, Gradle, `go test`, `dotnet test`…) and reads its output into a test tree. There is nothing to install beyond what the project already uses.
|
||
|
||
## Run tests
|
||
|
||
<Steps>
|
||
<Step title="From the gutter">
|
||
Click the ▶ icon next to a test, a test class or a test module and choose **Run '…'** or **Debug '…'**. After a run,
|
||
the icon turns green or red to show that test's last result.
|
||
</Step>
|
||
<Step title="From the caret">
|
||
**Run › Run Context Configuration** (`⌃⇧R` / `Ctrl+Shift+F10`) runs the test at the caret, or all tests in the
|
||
current file.
|
||
</Step>
|
||
<Step title="A whole directory">
|
||
Right-click a test directory in the Project view and choose **Run '…'** to run the tests inside it.
|
||
</Step>
|
||
<Step title="Everything">
|
||
Run a detected test configuration such as `cargo test`, `go test ./...`, `pytest` or the `test` script of
|
||
`package.json` from the run widget.
|
||
</Step>
|
||
</Steps>
|
||
|
||
Running a single test creates a temporary run configuration based on the project's detected test configuration (for example the `test` script for Jest, or the Maven / Gradle build for JUnit). See [Run configurations](/en/guide/run) to save it or change its options.
|
||
|
||
## Supported test frameworks
|
||
|
||
| Language | Gutter icons on | Runs with |
|
||
| --------------------------- | --------------------------------------------------------------------------------------------- | -------------------------------------------------------------- |
|
||
| Rust | `#[test]` functions, `mod tests` | `cargo test`, `cargo nextest` |
|
||
| JavaScript / TypeScript | `test`, `it`, `describe`, `suite`, `context` (also `.each`, `.only`, `.skip`) | Jest or Vitest via test script; Playwright; Cypress; Deno, Bun |
|
||
| Python | pytest `def test_*` and `class Test*`, unittest `TestCase` subclasses | pytest, Django `manage.py test` |
|
||
| Go | `func TestX(t *testing.T)`, benchmarks | `go test` |
|
||
| Java, Kotlin, Scala, Groovy | JUnit `@Test`, `@ParameterizedTest`, `@RepeatedTest`, `@TestFactory`, `@TestTemplate`; TestNG | Maven Surefire (`-Dtest=`) or Gradle (`--tests`) |
|
||
| PHP | PHPUnit test classes and methods, Pest `test` / `it` / `describe` | PHPUnit, Pest |
|
||
| Ruby | Minitest and Test::Unit classes, modules that hold them, `def test_*` | Minitest through `ruby` or `rake test` |
|
||
| C# | xUnit `[Fact]` / `[Theory]`, NUnit `[Test]` / `[TestCase]`, MSTest `[TestMethod]` | `dotnet test` (VSTest or Microsoft.Testing.Platform) |
|
||
|
||
RSpec has its own configuration type (**RSpec**) and a detected `rspec` configuration, but no gutter icons. Plugins can add test frameworks and report their results to the same test tree.
|
||
|
||
<Note>
|
||
For .NET projects that use Microsoft.Testing.Platform, run **Install TRX reporting** from the .NET tool window so
|
||
results show in the test tree. See [Build tools](/en/guide/build-tools).
|
||
</Note>
|
||
|
||
## The test results view
|
||
|
||
A test run opens a tab in the **Run** tool window with the test tree next to the console. Failed suites expand automatically.
|
||
|
||
- Click a test to see its own output in the console, or a class or suite to see its setup and teardown output followed by its tests'. **Show all output** above the console goes back to the whole run.
|
||
- Double-click, `Enter` or `F4` jumps to the test's source (**Jump to Source**).
|
||
- **Show Passed** and **Show Ignored** filter the tree. Passed tests are hidden by default; the filters are remembered.
|
||
- **⋯ › Test Runner Options › Select First Failed Test When Finished** selects the first failed test, with its output, when a run ends. It is off by default.
|
||
- **⋯ › Test Runner Options › Track Running Test** selects each test, with its output, as it starts while the run is in progress. It is on by default.
|
||
- Right-click a test or a selection for **Run '…'**, **Debug '…'** and **Jump to Source**.
|
||
- For an assertion failure with expected and actual values, **Show Diff** opens them side by side.
|
||
- For a Jest or Vitest snapshot mismatch, **Update Snapshot** (on the test or its file or suite, above the failure output, and in the gutter run menu) reruns just those tests with `-u`, so only their snapshots are rewritten.
|
||
|
||
Detected test configurations show results in the tree automatically. For your own configuration, turn on **Modify options › Show results in the test runner**.
|
||
|
||
## Rerun tests
|
||
|
||
| Action | macOS | Windows / Linux |
|
||
| ---------------------------------- | ----- | --------------- |
|
||
| **Rerun** (in the Run tool window) | `⌘R` | `Ctrl+F5` |
|
||
| **Rerun Failed Tests** | — | — |
|
||
|
||
**Rerun Failed Tests** (in the Run tool window toolbar and Find Action) runs only the tests that failed in the last run, using each tool's filter syntax. It works for Cargo, Jest / Vitest, Playwright, Cypress (with `@cypress/grep`), `node --test`, Mocha, pytest, Django, PHPUnit, Go, Maven / Gradle and .NET runs, and for plugin test frameworks.
|
||
|
||
Jasmine runs get it too, selecting the failed specs with `--filter=`.
|
||
|
||
### Watch mode (Jest, Vitest)
|
||
|
||
Turn on **Modify options › Watch for changes** in a Jest or Vitest test configuration, or the **Rerun Automatically** toggle in the test tree toolbar, to keep the runner watching (`jest --watchAll`, `vitest watch`). After each edit the tests run again in the same tab, and each cycle's results replace the previous ones in the tree. **Stop**, turning the toggle off, or closing the tab ends the watcher. Debug, **Rerun Failed Tests** and runs of selected tests run once. A script that runs `vitest run` is started as `vitest watch` through the package manager; a script that runs more than Jest or Vitest (`jest && eslint .`, `tsc && vitest run`) runs once.
|
||
|
||
### Rerun Automatically
|
||
|
||
For every other test runner, turn on **Rerun Automatically** in the test tree toolbar: after a file of the project is saved (by you or by autosave), the tab's tests run again once the delay passes (3 seconds by default; **More Actions › Set AutoTest Delay** offers 1 to 10). While a saved file has a syntax error nothing runs; the save that fixes it does. A test run in progress is not stopped: it runs again when it ends. The same goes for a debug session or another run of a configuration that doesn't allow parallel runs. An automatic run saves no other file. Only saves made in the editor count, so files written by the tests, the build or other programs don't start a run. The toggle lasts as long as the tab.
|
||
|
||
## Navigate between code and tests
|
||
|
||
**Navigate › Test** (`⌘⇧T` / `Ctrl+Shift+T`) jumps from a class to its tests and back, using common naming conventions (`FooTest`, `test_foo.py`, `foo.test.ts`…) and the project's source and test roots. With several matches it shows a chooser. With none, **Create New Test…** creates one from the file templates.
|
||
|
||
## Coverage
|
||
|
||
To see which lines the tests execute, run them with coverage. See [Coverage](/en/guide/coverage).
|