Using 3rd party dependencies in plugin's unit tests Follow
Answered
Hello,
Is it possible to use class files from the jar files, which my plugin depends on, in the unit tests or I can only add *.java files via myFixture.configure* methods when extending LightCodeInsightFixtureTestCase? I would like to create Psi structure from that dependency to see how my plugin processes it instead of copying the dependency source code into the plugin source code.
Thanks,
Anton
Please sign in to leave a comment.
You can setup the environment by providing your custom LightProjectDescriptor and add all required SDK/Libraries/... see org.jetbrains.idea.devkit.kotlin.inspections.missingApi.project.PluginProjectWithIdeaJdkDescriptor#configureModule in DevKit plugin for sample
Yann, thank you for the advice. I have tried that approach however I can't seem to be able to obtain PsiClass'es for the dependency classes through myFixture.findClass(). Is that not possible?
Do I have to extract the source files from the corresponding jar and add them explicitly to the test via myFixture.configureByFiles()?
com.intellij.testFramework.fixtures.impl.JavaCodeInsightTestFixtureImpl#findClass was changed about one year ago (331df898f8d1a0ae2175ea0e865de457d6a8de1a) to use "allScope" instead of "ProjectScope.getProjectScope" (which would not include library classes) - so it should work (given you use recent SDK). Otherwise, most probably something is not working with your library setup.
Got it working now -- I should have been passing the model to PsiTestUtil.addProjectLibrary() method from LightProjectDescriptor.configureModel() instead of the module.
Thanks for your help!
You're welcome, glad it works now
Yann, one more question, please. Is it possible to somehow plug in the source code for those dependencies, so that in my unit tests I could get full-fledged support of Psi parsers using PsiJavaFileImpl instead of ClsFileImpl?
I have tried copy-pasting some code from PsiTestUtil to invoke addProjectLibrary with an additional argument pointing to the sources zip or folder (the corresponding method is private) but it didn't seem to help.