简体   繁体   English

Intellij 插件开发和 Kotlin 测试

[英]Intellij plugin development & Kotlin tests

I'm trying to develop an intellij plugin written in kotlin - I'm struggling to find any examples of unit tests for the plugin that are written in kotlin, or even java ones with test data that are written using gradle rather than the older dev SDK. I'm trying to develop an intellij plugin written in kotlin - I'm struggling to find any examples of unit tests for the plugin that are written in kotlin, or even java ones with test data that are written using gradle rather than the older dev SDK。 Is anyone able to point to a demo application with unit tests?有没有人能够指出带有单元测试的演示应用程序? (For inspections, ideally) (理想情况下,用于检查)

These come out of the box now if you use the template: https://github.com/JetBrains/intellij-platform-plugin-template如果您使用模板,这些现在开箱即用: https://github.com/JetBrains/intellij-platform-plugin-template

Here's one of the tests in Kotlin:这是 Kotlin 中的一项测试:

package org.jetbrains.plugins.template

import com.intellij.ide.highlighter.XmlFileType
import com.intellij.psi.xml.XmlFile
import com.intellij.testFramework.TestDataPath
import com.intellij.testFramework.fixtures.BasePlatformTestCase
import com.intellij.util.PsiErrorElementUtil

class MyPluginTest : BasePlatformTestCase() {

    fun testXMLFile() {
        val psiFile = myFixture.configureByText(XmlFileType.INSTANCE, "<foo>bar</foo>")
        val xmlFile = assertInstanceOf(psiFile, XmlFile::class.java)

        assertFalse(PsiErrorElementUtil.hasErrors(project, xmlFile.virtualFile))

        assertNotNull(xmlFile.rootTag)

        xmlFile.rootTag?.let {
            assertEquals("foo", it.name)
            assertEquals("bar", it.value.text)
        }
    }
}

The plugin documentation also provides more relevant info for testing: https://plugins.jetbrains.com/docs/intellij/writing-tests.html插件文档还提供了更多相关的测试信息: https://plugins.jetbrains.com/docs/intellij/writing-tests.html

Also, here are some unit tests written in Java for the JUnit IntelliJ plugin https://github.com/JetBrains/intellij-community/blob/master/plugins/junit/test/com/intellij/execution/junit/JUnitDetectionTest.java Also, here are some unit tests written in Java for the JUnit IntelliJ plugin https://github.com/JetBrains/intellij-community/blob/master/plugins/junit/test/com/intellij/execution/junit/JUnitDetectionTest.java

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM