Light and Heavy Tests
tip
Configuring Test Frameworks (2024.2+)All required test-framework dependencies must be declared explicitly.
Plugin tests run in a real, rather than mocked, IntelliJ Platform environment and use real implementations for most application and project services.
Loading and initializing all the project components and services for a project to run tests is a relatively expensive operation, and it is desired to avoid doing it for each test. Dependently on the loading and execution time, we make a difference between light tests and heavy tests available in the IntelliJ Platform test framework:
Light tests reuse a project from the previous test run when possible.
Heavy tests create a new project for each test.
Light and heavy tests use different base classes or fixture classes, as described below.
note
Because of the performance difference, we recommend plugin developers to write light tests whenever possible.
The standard way of writing a light test is to extend one of the following classes:
Use LightPlatformTestCase
or BasePlatformTestCase
for tests that don't have any dependency on Java functionality.
For 2019.2 and earlier, use LightPlatformCodeInsightFixtureTestCase
.
Examples:
tip
Java Test Framework (2024.2+)An explicit dependency on
TestFramework.Plugin.Java
is required, see test-framework dependencies.
For tests that require the Java PSI or related functionality:
LightJavaCodeInsightFixtureTestCase
for JUnit 3LightJavaCodeInsightFixtureTestCase4
for JUnit 4 (2021.1 and later)LightJavaCodeInsightFixtureTestCase5
for JUnit 5 (2021.1 and later)
For 2019.2 and earlier, use LightCodeInsightFixtureTestCase
.
Examples:
PatternValidatorTest
(JUnit 3)JavaCtrlMouseTest
(JUnit 4)MissingJavadocHighlightingTest
(JUnit 5)
tip
See How to test a JVM language? on how to set up your test environment to obtain the required Mock JDK automatically.
When writing a light test, it is possible to specify the requirements of the project used in test, such as the module type, the configured SDK, facets, libraries, etc. It is done by extending the LightProjectDescriptor
class and returning the project descriptor (usually stored in static final
field) from getProjectDescriptor()
.
Before executing each test, the project instance will be reused if the test case returns the same project descriptor as the previous one or recreated if the descriptor is different (equals() = false
).
When testing JVM languages, see also DefaultLightProjectDescriptor
.
The standard way of writing a heavy test is to extend HeavyPlatformTestCase
.
note
In 2019.3,
PlatformTestCase
has been renamed toHeavyPlatformTestCase
reflecting its "heavy test" characteristics.
Examples:
If a test requires a multi-module project, using a heavy test is required. The following code snippet presents a multi-module Java project setup:
TestFixtureBuilder<IdeaProjectTestFixture> projectBuilder =
IdeaTestFixtureFactory.getFixtureFactory().createFixtureBuilder(getName());
// fixture must be created before adding modules:
myFixture = JavaTestFixtureFactory.getFixtureFactory()
.createCodeInsightFixture(projectBuilder.getFixture());
// add and configure modules:
JavaModuleFixtureBuilder<?> builder1 =
projectBuilder.addModule(JavaModuleFixtureBuilder.class);
// optionally, configure the module, e.g.:
// builder1.setLanguageLevel(...);
// builder1.addJdk(...);
JavaModuleFixtureBuilder<?> builder2 =
projectBuilder.addModule(JavaModuleFixtureBuilder.class);
// configure another module...
Thanks for your feedback!