[英]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)
(理想情况下,用于检查)
Some theory:一些理论:
Code samples:代码示例:
Article on running Kotlin Unit tests with Gradle关于使用 Gradle 运行 Kotlin 单元测试的文章
A tutorial on building apps with Spring Boot and Kotlin with a section on testing with Junit5 使用 Spring Boot 和 Kotlin 构建应用程序的教程,其中包含使用 Junit5 进行测试的部分
Custom Gradle plugin example自定义Gradle 插件示例
Hope this helps.希望这可以帮助。
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.