一键导入
writing-tests
Guidelines for writing tests in IntelliJ codebase. Use when creating new test classes or test methods.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Guidelines for writing tests in IntelliJ codebase. Use when creating new test classes or test methods.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
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.
Extract an optional dependency from a plugin module into a new content module. Use when making a library dependency optional by separating integration code into its own module.
Extract an optional dependency from a plugin module into a new content module. Use when making a library dependency optional by separating integration code into its own module.
How to manage module dependencies in IntelliJ codebase. Use when adding or modifying module dependencies in iml files.
Guidelines for structuring and developing IntelliJ remote development modules. Use when working on Remote Development features.
| 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