Plugin testing accesses to Library and Java classes

Hi,

I developing a plugin for IntelliJ IDEA that does something within Java classes. It also needs dependency on a another Library during testing.

 

Up until now I have been adding the sources of the Library as sources to the test. However, I think that this is not correct. What would be the correct way to add a jar as a dependency in my tests?

 

Connected to this is, how can I make my tests see the dependency to the Java language. Currently, I don't see the Java classes during tests.

 

Thanks

Filip

0
5 comments

Hi Filip!

Do you mean that you don't see j.l.Object? This could only mean that you don't have jdk set up. What test case do you extend/what test fixture do you use? Normally you need to provide mock jdk and if you want to add a library, you can use utility like com.intellij.testFramework.PsiTestUtil#addLibrary(com.intellij.openapi.module.Module, java.lang.String)

Anna

0
Avatar
Permanently deleted user

Hey Anna,

 

Yes I don't see j.l.Object, or j.l.Integer. I am using the gradle intellij plugin. I am extending the LightFixtureCompletionTestCase. Isn't that one automatically configured with JDK or I should do something else?

 

Thanks for the info for the library information. I'll try it out. In any case I think that a better mechanism is needed when working with the gradle plugin

 

Cheers,

Filip

0

Hi Filip,

 

What do you mean by a better mechanism for working with gradle plugin? As far as I understand your question has nothing to do with Gradle or gradle-intellij-plugin at all.

0
Avatar
Permanently deleted user

Hey Alexander,

 

You are right, it is not connected to the plugin. However, the com.intellij.testFramework.PsiTestUtil#addLibrary(com.intellij.openapi.module.Module, java.lang.String) the string is an expected jar. Which means that the test utils from IntelliJ are expecting the plugins to have jars in their sources (or some way to get them easily). With the Gradle IntelliJ plugin the jars are managed by Gradle and I would not like to use those paths in the tests. That is why I said that the mechanism there should be better. Maybe I don't completely understand how I should use the addLibrary.

 

In any case, I am still having issues with the java lang classes.

 

Cheers,

Filip

0

Still don't understand how it's related to Gradle, sorry. `com.intellij.testFramework.PsiTestUtil#addLibrary(com.intellij.openapi.module.Module, java.lang.String)` accepts a path to Jar and it doesn't matter who manages this jar and whether it's part of your project model. It's just a path to some file, it's not required to have it in sources.

> In any case, I am still having issues with the java lang classes.

As Anna said, you should provide a mockSdk for it. Please see other implementations ofLightFixtureCompletionTestCase in community edition sources.

0

Please sign in to leave a comment.