LightJavaCodeInsightFixtureTestCase - resolve methods are returning null always
Answered
I'm trying to test my custom content assist for Java extending LightJavaCodeInsightFixtureTestCase , but sometimes it does not work as expected.
Methods like PsiClassType.resolve() or PsiMethodCallExpression.multiResolve() always returns null for me somewhy, even when called for JDK classes.
Am I dong smth wrong, or I need to use some other base class for my tests?
Please sign in to leave a comment.
Please make sure _all_ required classes/interfaces/.. are present in your test, see also https://jetbrains.org/intellij/sdk/docs/tutorials/writing_tests_for_plugins/tests_prerequisites.html#set-the-run-configuration-parameters
Sorry, how could I ensure their presence? In my test I'm using only dependencies from JDK, so JDK should be enough.
And a second Q - resolution wouldn't work without specifying an absolute path to the local Community installation? Not a big deal on my machine, but can be a problem, when I'll set this up on Travis/Jenkins...
PS: Unfortunately I wasn't able to dig to the place, where resolving initially goes wrong - possibly you can give me some location, where I can put a breakpoint to see what happens?
You'll need to setup mockJDK containing required classes, see above link in SDK Docs and this discussion https://intellij-support.jetbrains.com/hc/en-us/community/posts/360009436599-Cannot-resolve-symbol-with-official-example-code
Basically, if "findClass(FQNOfExpectedType)" fails you'll need to add that class in addition as "dummy" (containing only class declaration/relevant method signatures and all dependent types) in your test via "addClass" or similar.
Tanks. It looks like that's enough to create and retuurn custom ProjectDescriptor, returning Sdk created using JavaSdk,createJdk() with IdeaTestUtil.requireRealJdkHome() passed. Of course, "java.home" should be set.
In that case, no need to have build.gradle changed for each machine.
The idea of mockJDK is to reduce load/indexing time required for tests by including only most often used classes from JDK.