实现或修改 IntelliJ `AnAction`,并在 `plugin.xml` 中注册。将显示名称和说明写入消息资源文件,按需设置图标,并通过事件协程作用域启动挂起任务,避免同步处理阻塞 IDE。
- 为 IDE 菜单添加操作
- 修改操作注册或图标
- 整理操作名称和说明
为IntelliJ代码库编写和审查JUnit 5测试,指导选择对应测试模块、使用项目夹具与生命周期注解,并在明确的测试范围内处理协程和UI线程工作。
Write IntelliJ JUnit 5 tests with fixtures, lifecycle, and EDT.
实测评分 未实测
查看安装方法此技能用于为IntelliJ代码库编写和审查JUnit 5测试。它会指导你选择与生产模块对应的测试模块,并使用@TestApplication、项目夹具和@TestDisposable等方式组织测试。设置和清理使用JUnit 5生命周期注解;协程测试则以timeoutRunBlocking作为边界。它还会说明如何只在合适的调度器上执行UI操作,以及如何用完成信号代替固定等待时间。
为IntelliJ模块添加测试,或审查现有测试的夹具、资源释放和UI线程使用时,可以使用此技能。它也适用于从JUnit 4风格迁移到JUnit 5,或编写包含协程的测试。
适用范围是IntelliJ代码库中的测试。命令行运行示例为./tests.cmd --module <test-module> --test com.example.MyTest。
本介绍由 AI(OpenAI Codex)根据公开的 SKILL.md 撰写。准确的规格请查看下方原文。
AI 根据 SKILL.md 的内容检查了需要注意的操作和使用前提。评分只依据实际运行的结果(实测对比)。
不计入评分。 由 AI(OpenAI Codex)于 2026年10月28日 评估。仅供参考,安装前请同时查看原文。
安装前可以查看交给 AI 代理的指令内容。
Guidelines for writing tests in IntelliJ IDEA codebase.
For examples, see community/platform/testFramework/junit5/test/showcase/.
Put a test in the test module associated with the production module it exercises. Do not place it in a downstream module merely because
that module has the production module on its test classpath. Check the production module's .iml file and neighboring tests before adding
a new test.
In particular, code in org.jetbrains.intellij.build.io under community/build/tasks belongs to
intellij.idea.community.build.tasks.tests (community/build/tasks/test), not intellij.platform.buildScripts.tests. The
BUILD_SCRIPTS_PLATFORM_TESTS group deliberately excludes org.jetbrains.intellij.build.io.* to avoid matching build-task tests by class
name across module boundaries. Putting such a test in the build-scripts test module leaves it outside every community test group and causes
UltimateProjectTestsStructureTest to fail.
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 com.intellij.testFramework.common.timeoutRunBlocking as the coroutine boundary. It has a 10-second default timeout, so a
suspended test fails quickly with a coroutine-aware thread dump. Do not add a JUnit @Timeout to such a test. The two timeouts
duplicate each other, and the @Timeout gives a worse diagnostic.
Keep setup, background work, and assertions off the UI thread. Move only Swing operations into a small
withContext(Dispatchers.UI) block:
@Test
fun updatesLabel(): Unit = timeoutRunBlocking {
val value = loadValue()
val actual = withContext(Dispatchers.UI) {
label.text = value
label.text
}
assertThat(actual).isEqualTo(value)
}
Dispatchers.UI is strict: it supplies UI-thread affinity without implicit model access. Use Dispatchers.EDT only when the tested
operation genuinely requires model or lock access and cannot be split from the UI operation. Keep write actions explicit.
Editor creation/disposal, editor document mutation, completion invocation, action-group expansion, and file-editor operations are common
model-backed exceptions. Keep their full synchronous lifecycle in a narrow Dispatchers.EDT block; do not construct on strict UI and
dispose later from a different dispatcher.
Do not use @RunInEdt, @RunMethodInEdt, runInEdtAndWait, or runInEdtAndGet in new tests. They hide the coroutine boundary,
move lifecycle methods and assertions onto EDT, and can accidentally grant model or write-intent access.
When a synchronous callback API cannot call a suspending function, use a narrow bounded adapter around that callback only:
timeoutRunBlocking(timeout = 10.seconds, context = Dispatchers.UI) {
createSwingComponent()
}
Prefer observable completion signals, flows, latches, or virtual time over sleeps. If polling is unavoidable, bound it and make the
predicate suspending so UI checks can use withContext(Dispatchers.UI) without nested blocking.
Use the enclosing test scope for launched work: pass this from timeoutRunBlocking/coroutineScope, or backgroundScope from
runTest, into the code under test. Create a standalone CoroutineScope(...) only when independent scope lifetime is itself under test;
parent it to the test job and cancel it in finally. Use delay freely with runTest virtual time, but do not use a real timing-only
delay as a completion signal.
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.common.timeoutRunBlocking - runs suspending test code with a 10-second default timeoutcom.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 - legacy EDT extension behavior; do not copy it for new testsTo run tests via command line, see TESTING.md.
Quick example:
./tests.cmd --module <test-module> --test com.example.MyTest
还没有评价。欢迎分享你的使用感受。
无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。
还没有评论。来写第一条吧。
实现或修改 IntelliJ `AnAction`,并在 `plugin.xml` 中注册。将显示名称和说明写入消息资源文件,按需设置图标,并通过事件协程作用域启动挂起任务,避免同步处理阻塞 IDE。
将 IntelliJ JPS 测试模块迁移到 Bazel,并排查仅在 Bazel 中出现的失败。根据症状检查依赖、插件、测试数据和 runfiles,重新生成并验证目标。
按 IntelliJ 项目规范编写或审查 Kotlin 和 Java 代码,涵盖语言选择、格式、密封类型、线程注解及控制流异常处理。
本指南帮助您按 IntelliJ 项目规则拆分更改并撰写提交信息:有工单时使用编号和变更说明,无工单时使用标签与子系统名,并在需要时说明原因和决定。
使用多个 Python 类型检查器比较代码片段或文件的类型推断和报错判断,并汇总各工具的结论、耗时与诊断信息,可保存为 Markdown 报告。
整理 Compose Desktop 界面中的状态和副作用,让可组合函数负责绘制,由展示器或协调器处理应用决策。了解状态归属、Effect、可复用组件接口、延迟列表键、动画和性能,适用于单项界面修改。