Testing Overview
Edit pageLast modified: 03 December 2024Most of the tests in the IntelliJ Platform codebase are model-level functional tests. What this means is the following:
The tests run in a headless environment that uses real production implementations for most components, except for many UI components.
The tests usually test a feature as a whole rather than individual functions that comprise its implementation.
The tests do not test the Swing UI and work directly with the underlying model instead (see also UI Tests).
Most tests take a source file or a set of source files as input data, execute a feature, and compare the output with expected results. Results can be specified as another set of source files, special markup in the input file, or directly in the test code.
The most significant benefit of this test approach is that tests are very stable and require very little maintenance once written, no matter how much the underlying implementation is refactored or rewritten.
In a product with 20+ years of a lifetime that has gone through many internal refactorings, we find that this benefit dramatically outweighs the downsides of slower test execution and more difficult debugging of failures compared to more isolated unit tests.
Mocks
Another consequence of our testing approach is that we do not provide a recommended approach to mocking. We have a few tests in our codebase that use JMock. Still, in general, we find it difficult to mock all the interactions with IntelliJ Platform components that your plugin class will need to have. We recommend working with real components instead. See also How to replace component/service in tests? and How to replace extension points in tests?.
UI Tests
UI tests using the dedicated intellij-ui-test-robot library can be run via Gradle tasks:
Use testIdeUi
task.
Use runIdeForUiTests
task.
Do not use platform/testGuiFramework, as it is reserved for internal use.
The IntelliJ Platform integration testing framework, used internally for performance, functional, and UI tests, is now accessible to help streamline and enhance your plugin testing experience.
Topics
note
Check out this step-by-step tutorial teaching how to write and run automated tests for your custom language plugin. Also, code samples comparing_string_references_inspection and conditional_operator_intention demonstrate using tests.
note
Something missing?If a topic you are interested in is not covered in the above sections, let us know via the Was this page helpful? feedback form below or other channels.
Please be specific about the topics and reasons for adding them, and leave your email in case we need more details. Thanks for your feedback!
Thanks for your feedback!