4.1 KiB

Light and Heavy Tests

Introduction to light tests reusing a single project for multiple tests, and heavy tests creating a new project for each test.

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 we want 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.

Because of the performance difference, we recommend plugin developers to write light tests whenever possible.

{style="note"}

Light Tests

The standard way of writing a light test is to extend one of the following classes:

BasePlatformTestCase for tests that don't have any dependency on Java functionality.

For 2019.2 and earlier, use LightPlatformCodeInsightFixtureTestCase.

For tests that require the Java PSI or related functionality:

  • LightJavaCodeInsightFixtureTestCase for JUnit3
  • LightJavaCodeInsightFixtureTestCase4 for JUnit4 (2021.1 and later)
  • LightJavaCodeInsightFixtureTestCase5 for JUnit5 (2021.1 and later)

For 2019.2 and earlier, use LightCodeInsightFixtureTestCase.

See on how to set up your test environment to obtain the required Mock JDK automatically.

LightProjectDescriptor

When writing a light test, you can specify the project's requirements that you need to have in your test, such as the module type, the configured SDK, facets, libraries, etc. You do so by extending the LightProjectDescriptor class and returning your 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).

Heavy Tests

If you need to set up a multi-module project for your tests, you must write a heavy test.

{style="note"}

In 2019.3, PlatformTestCase has been renamed to HeavyPlatformTestCase reflecting its "heavy test" characteristics.

{style="note"}

The setup code for a multi-module Java project looks something like that:

TestFixtureBuilder<IdeaProjectTestFixture> projectBuilder =
        IdeaTestFixtureFactory.getFixtureFactory().createFixtureBuilder(getName());

// Repeat the following line for each module
JavaModuleFixtureBuilder moduleFixtureBuilder =
        projectBuilder.addModule(JavaModuleFixtureBuilder.class);

myFixture = JavaTestFixtureFactory.getFixtureFactory()
        .createCodeInsightFixture(projectBuilder.getFixture());