Testing - psiFacade contains no packages
I am working on a simple plugin that filters the console output and creates links to classes when a string with a fully qualified package name and class appears.
I am now trying to test the plugin using LightJavaCodeInsightFixtureTestCase. I have added two Java files to test/resources and have written a test case. I am passing the project (obtained with getProject() in my test) to my objects. I can now see that this has worked, since PsiShortNamesCache.getInstance(this.project).getAllClassNames() lists all classes. However obtaining a class or a package does not work via the psiFacade: JavaPsiFacade.getInstance(this.project).findClass("pack.age.myclazz", new ProjectScopeBuilderImpl(project).buildProjectScope()).
How do I set up the fixture correctly to obtain a project with this package?
Please sign in to leave a comment.
Could you please share link to your project? There are too many variables that could influence this.
Here is a sample project I've set up: https://github.com/Clindbergh/samplePluginDemonstratingPsiFacadeTesting
Thanks. Your test doesn't invoke required setup of test data files to use.
e.g. add
myFixture.copyDirectoryToProject("", "");
as first line in each test method to copy complete `src/test/resources` folder into temp project.
Reference: https://plugins.jetbrains.com/docs/intellij/test-project-and-testdata-directories.html