with one click
writing-tests
Guidelines for writing tests in IntelliJ codebase. Use when creating new test classes or test methods.
Menu
Guidelines for writing tests in IntelliJ codebase. Use when creating new test classes or test methods.
Comprehensive testing reference for running tests in IntelliJ codebase via tests.cmd. Use when running, debugging, or troubleshooting test execution.
Guidelines for implementing IntelliJ actions (AnAction). Use those rules when you need to create or change an action in the intellij platform.
Comprehensive testing reference for running tests in IntelliJ codebase via tests.cmd. Use when running, debugging, or troubleshooting test execution.
Guidelines for implementing IntelliJ actions (AnAction). Use those rules when you need to create or change an action in the intellij platform.
Pluginize a Product DSL module set by hand-writing a wrapper plugin module next to its feature modules. Use when promoting modules out of an aggregate module set (e.g. `essential`, `ide.common`) into a bundled plugin so products can include or omit them through normal plugin wiring, when updating bundled plugin registration for such a wrapper, or when fixing tests whose plugin loading logs show a missing wrapper plugin for a former module set.
Pluginize a Product DSL module set by hand-writing a wrapper plugin module next to its feature modules. Use when promoting modules out of an aggregate module set (e.g. `essential`, `ide.common`) into a bundled plugin so products can include or omit them through normal plugin wiring, when updating bundled plugin registration for such a wrapper, or when fixing tests whose plugin loading logs show a missing wrapper plugin for a former module set.
| name | writing-tests |
| description | Guidelines for writing tests in IntelliJ codebase. Use when creating new test classes or test methods. |
Guidelines for writing tests in IntelliJ IDEA codebase.
For examples, see community/platform/testFramework/junit5/test/showcase/.
Use JUnit 5 with @TestApplication annotation instead of extending LightJavaCodeInsightFixtureTestCase.
Why JUnit 5:
@TestDisposable, @RegistryKey) instead of manual setup/teardownUse companion object fixtures shared between all tests:
@TestApplication
internal class MyTest {
companion object {
private val projectFixture = projectFixture()
private val moduleFixture = projectFixture.moduleFixture("src")
}
private val project get() = projectFixture.get()
private val module get() = moduleFixture.get()
}
Use JUnit 5 lifecycle annotations for setup and teardown:
@TestApplication
internal class MyTest {
companion object {
@JvmStatic
@BeforeAll
fun setUpClass() {
// Once before all tests in class
}
@JvmStatic
@AfterAll
fun tearDownClass() {
// Once after all tests in class
}
}
@BeforeEach
fun setUp() {
// Before each test method
}
@AfterEach
fun tearDown() {
// After each test method
}
}
Note: Prefer @TestDisposable over manual @AfterEach cleanup for resources.
Use @TestDisposable annotation to inject test-scoped disposables (created before each test, disposed after):
@TestDisposable
lateinit var disposable: Disposable
// Or as parameter
@Test
fun myTest(@TestDisposable disposable: Disposable) { ... }
Use @RegistryKey annotation instead of Registry.get().setValue():
@Test
@RegistryKey(key = "my.registry.key", value = "true")
fun testWithRegistryEnabled() { ... }
Use @SystemProperty annotation instead of System.setProperty():
@Test
@SystemProperty(propertyKey = "my.property", propertyValue = "value")
fun testWithSystemProperty() { ... }
Use @RunInEdt annotation to run test methods in EDT:
@TestApplication
@RunInEdt
class MyEdtTest {
@Test
fun testInEdt() { ... }
}
// Or for specific methods only
@TestApplication
@RunInEdt(allMethods = false)
class MyTest {
@Test
@RunMethodInEdt
fun testInEdt() { ... }
}
com.intellij.testFramework.junit5.TestApplication - initializes shared applicationcom.intellij.testFramework.junit5.TestDisposable - injects test disposablescom.intellij.testFramework.junit5.RegistryKey - sets registry valuescom.intellij.testFramework.junit5.SystemProperty - sets system propertiescom.intellij.testFramework.junit5.RunInEdt - runs tests in EDTcom.intellij.testFramework.junit5.fixture.projectFixture - creates project fixturescom.intellij.testFramework.junit5.fixture.moduleFixture - creates module fixturesJUnit5ProjectFixtureTest.kt - project fixture patternsJUnit5DisposableTest.kt - disposable injectionJUnit5SystemPropertyTest.kt - system property usageJUnit5RunInEdtTest.java - EDT executionTo run tests via command line, see TESTING.md.
Quick example:
./tests.cmd -Dintellij.build.test.patterns=*MyTest