The docs are not sufficient for me to create any working unit tests, every class referenced in the docs doesn’t exist and the dependency I need to pull isn’t mentioned anywhere!
I’m trying to run a test with Psi and when I try and resolve java.lang.String I get class not found exception…
What am I missing?
I see in the docs you need something like
test {
systemProperty(“idea.home.path”, “/path/to/intellij-community-sources”)
}
but I’m unsure what intellij-community-sources it supposed to mean? I see on github people use stuff like
And now you’re ready to starting writing Unit+Functional tests.
This is example of my own:
import com.intellij.testFramework.fixtures.BasePlatformTestCase
class AppendTransformerTest : BasePlatformTestCase() {
fun testProcessText() {
val transformer = AppendTransformer("value/to/append")
val result = transformer.process("new value", myFixture.project)
val expected = "value/to/append/new value"
assertEquals(expected, result)
}
}
If you’re looking for JUnit annotations, I you those from jupiter:
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.TestInstance
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.Arguments
import org.junit.jupiter.params.provider.MethodSource
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
abstract class BaseFeatureTest : BasePlatformTestCase() {
abstract fun dataDefaultCompletion(): Collection<Arguments>
@ParameterizedTest
@MethodSource("dataDefaultCompletion")
open fun testCompletion(definitions: String, code: String, completion: Array<String>) {
addXmlDefinition(definitions)
loadPhpContent(code)
assertCompletionContains(*completion)
}
@BeforeEach
override fun setUp() {
super.setUp()
}
@AfterEach
override fun tearDown() {
super.tearDown()
}
}
/**
* Test class for KBuilder.fromPsiType functionality
*/
class SimpleTest : LightJavaCodeInsightFixtureTestCase() {
fun testCanAccessJava() {
val type = PsiType.getTypeByName("java.lang.String", project, GlobalSearchScope.allScope(project))
val result = (type as PsiClassType).resolve()
assertNotNull(result)
assertEquals(result!!.qualifiedName, "java.lang.String")
}
}