簡體   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。 有沒有人能夠指出帶有單元測試的演示應用程序? (理想情況下,用於檢查)

如果您使用模板,這些現在開箱即用: https://github.com/JetBrains/intellij-platform-plugin-template

這是 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)
        }
    }
}

插件文檔還提供了更多相關的測試信息: 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM