How to unit-test PSI-related code

Hi Jetbrains,

Could you please give me a hint, how to unit-test PSI-related code, e.g. my
Type Refactoring plug-in?

Thanks in advance,
Tom

11 comments
Comment actions Permalink

No ideas?

Tom

0
Comment actions Permalink

Tom

>

how to unit-test PSI-related code



IDEA's testFramework is what you need, but it's in a poor condition
right now (broken ?).
Dave K should know more, as he uses it in the Rearranger plugin.


Alain

0
Comment actions Permalink

com.intellij.testFramework package contains necessary base testcases. Look
at LightIdeaTestCase, LightCodeInsightTestCase for example.

-


Maxim Shafirov
http://www.jetbrains.com
"Develop with pleasure!"

No ideas?

Tom




0
Comment actions Permalink

In order to make LightIdeaTestCase testcases work:
- add the following jars to either your project or IDEA SDK libraries
/lib/idea.jar /plugins/cvsIntegration/lib/cvsIntegration.jar /plugins/weblogicIntegration/lib/weblogicIntegration.jar /plugins/tomcat/lib/tomcat.jar - add the following VM paramter to the run config of your tests -Xbootclasspath/p:]]>/lib/boot.jar

0
Comment actions Permalink

Maas van den Berg wrote:

>In order to make LightIdeaTestCase testcases work:

>

Now, it compiles , and run, but I get a stranger error:
java.lang.SecurityException: Prohibited package name: java.lang
Any clue?

(This exact same code used to run flawlessy 1 year ago)

Alain

full stacktrace:

java.lang.SecurityException: Prohibited package name: java.lang
at java.lang.ClassLoader.defineClass(ClassLoader.java:524)
at
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:251)
at java.net.URLClassLoader.access$100(URLClassLoader.java:55)
at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
at
com.intellij.psi.impl.source.CharTableImpl.getId(CharTableImpl.java:32)
at
com.intellij.psi.impl.source.tree.LeafElementImpl.(LeafElementImpl.java:22) at com.intellij.psi.impl.source.tree.LeafPsiElement.(LeafPsiElement.java:14) at com.intellij.psi.impl.source.tree.java.PsiKeywordImpl.]]>(PsiKeywordImpl.java:5)
at
com.intellij.psi.impl.source.tree.Factory.createLeafElement(Factory.java:315)
at
com.intellij.psi.impl.source.parsing.ParseUtil.createTokenElement(ParseUtil.java:65)
at
com.intellij.psi.impl.source.parsing.DeclarationParsing.parseModifierList(DeclarationParsing.java:495)
at
com.intellij.psi.impl.source.parsing.DeclarationParsing.parseDeclaration(DeclarationParsing.java:554)
at
com.intellij.psi.impl.source.parsing.FileTextParsing.parseFileText(FileTextParsing.java:64)
at
com.intellij.psi.impl.source.parsing.FileTextParsing.parseFileText(FileTextParsing.java:36)
at
com.intellij.psi.impl.source.tree.JavaFileChameleonElement.transform(JavaFileChameleonElement.java)
at
com.intellij.psi.impl.source.parsing.ChameleonTransforming.transform(ChameleonTransforming.java:21)
at
com.intellij.psi.impl.source.parsing.ChameleonTransforming.transformChildren(ChameleonTransforming.java:27)
at
com.intellij.psi.impl.source.parsing.ChameleonTransforming.transformChildren(ChameleonTransforming.java:25)
at
com.intellij.psi.impl.source.tree.CompositeElement.countChildren(CompositeElement.java:165)
at
com.intellij.psi.impl.source.tree.CompositeElement.getChildrenAsPsiElements(CompositeElement.java:19)
at
com.intellij.psi.impl.source.PsiJavaFileBaseImpl.getClasses(PsiJavaFileBaseImpl.java:180)
at
com.ravet.intellij.testFramework.AbstractRegionFoldingTestCaseX.getFileFirstClass(AbstractRegionFoldingTestCaseX.java:31)
at
com.ravet.intellij.test_slow.Test_SimpleMethodFolding.test2_afterTheAction(Test_SimpleMethodFolding.java:54)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at
com.intellij.testFramework.LightCodeInsightTestCase.access$101(LightCodeInsightTestCase.java:12)
at
com.intellij.testFramework.LightCodeInsightTestCase$2.run(LightCodeInsightTestCase.java:5)
at
com.intellij.openapi.command.impl.CommandProcessorImpl.executeCommand(CommandProcessorImpl.java:13)
at
com.intellij.openapi.command.impl.CommandProcessorImpl.executeCommand(CommandProcessorImpl.java:5)
at
com.intellij.testFramework.LightCodeInsightTestCase$1.run(LightCodeInsightTestCase.java)
at
com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:97)
at
com.intellij.testFramework.LightCodeInsightTestCase.runTest(LightCodeInsightTestCase.java:43)
at
com.intellij.testFramework.LightIdeaTestCase.d(LightIdeaTestCase.java:68)
at
com.intellij.testFramework.LightIdeaTestCase.access$400(LightIdeaTestCase.java:19)
at
com.intellij.testFramework.LightIdeaTestCase$6.run(LightIdeaTestCase.java:9)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:171)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:454)
at
java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:234)
at
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:178)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:170)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)

0
Comment actions Permalink

-Xbootclasspath/p:$/lib/boot.jar

-


Maxim Shafirov
http://www.jetbrains.com
"Develop with pleasure!"

Maas van den Berg wrote:

>> In order to make LightIdeaTestCase testcases work:
>>

Now, it compiles , and run, but I get a stranger error:
java.lang.SecurityException: Prohibited package name: java.lang
Any clue?
(This exact same code used to run flawlessy 1 year ago)

Alain

full stacktrace:

java.lang.SecurityException: Prohibited package name: java.lang
at java.lang.ClassLoader.defineClass(ClassLoader.java:524)
at
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123
)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:251)
at java.net.URLClassLoader.access$100(URLClassLoader.java:55)
at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
at
com.intellij.psi.impl.source.CharTableImpl.getId(CharTableImpl.java:32
)
at
com.intellij.psi.impl.source.tree.LeafElementImpl.<init>(LeafElementIm
pl.java:22)
at
com.intellij.psi.impl.source.tree.LeafPsiElement.<init>(LeafPsiElement
.java:14)
at
com.intellij.psi.impl.source.tree.java.PsiKeywordImpl.<init>(PsiKeywor
dImpl.java:5)
at
com.intellij.psi.impl.source.tree.Factory.createLeafElement(Factory.ja
va:315)
at
com.intellij.psi.impl.source.parsing.ParseUtil.createTokenElement(Pars
eUtil.java:65)
at
com.intellij.psi.impl.source.parsing.DeclarationParsing.parseModifierL
ist(DeclarationParsing.java:495)
at
com.intellij.psi.impl.source.parsing.DeclarationParsing.parseDeclarati
on(DeclarationParsing.java:554)
at
com.intellij.psi.impl.source.parsing.FileTextParsing.parseFileText(Fil
eTextParsing.java:64)
at
com.intellij.psi.impl.source.parsing.FileTextParsing.parseFileText(Fil
eTextParsing.java:36)
at
com.intellij.psi.impl.source.tree.JavaFileChameleonElement.transform(J
avaFileChameleonElement.java)
at
com.intellij.psi.impl.source.parsing.ChameleonTransforming.transform(C
hameleonTransforming.java:21)
at
com.intellij.psi.impl.source.parsing.ChameleonTransforming.transformCh
ildren(ChameleonTransforming.java:27)
at
com.intellij.psi.impl.source.parsing.ChameleonTransforming.transformCh
ildren(ChameleonTransforming.java:25)
at
com.intellij.psi.impl.source.tree.CompositeElement.countChildren(Compo
siteElement.java:165)
at
com.intellij.psi.impl.source.tree.CompositeElement.getChildrenAsPsiEle
ments(CompositeElement.java:19)
at
com.intellij.psi.impl.source.PsiJavaFileBaseImpl.getClasses(PsiJavaFil
eBaseImpl.java:180)
at
com.ravet.intellij.testFramework.AbstractRegionFoldingTestCaseX.getFil
eFirstClass(AbstractRegionFoldingTestCaseX.java:31)
at
com.ravet.intellij.test_slow.Test_SimpleMethodFolding.test2_afterTheAc
tion(Test_SimpleMethodFolding.java:54)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.j
ava:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccess
orImpl.java:25)
at
com.intellij.testFramework.LightCodeInsightTestCase.access$101(LightCo
deInsightTestCase.java:12)
at
com.intellij.testFramework.LightCodeInsightTestCase$2.run(LightCodeIns
ightTestCase.java:5)
at
com.intellij.openapi.command.impl.CommandProcessorImpl.executeCommand(
CommandProcessorImpl.java:13)
at
com.intellij.openapi.command.impl.CommandProcessorImpl.executeCommand(
CommandProcessorImpl.java:5)
at
com.intellij.testFramework.LightCodeInsightTestCase$1.run(LightCodeIns
ightTestCase.java)
at
com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(A
pplicationImpl.java:97)
at
com.intellij.testFramework.LightCodeInsightTestCase.runTest(LightCodeI
nsightTestCase.java:43)
at
com.intellij.testFramework.LightIdeaTestCase.d(LightIdeaTestCase.java:
68)
at
com.intellij.testFramework.LightIdeaTestCase.access$400(LightIdeaTestC
ase.java:19)
at
com.intellij.testFramework.LightIdeaTestCase$6.run(LightIdeaTestCase.j
ava:9)
at
java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:171)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:454)
at
java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThr
ead.java:234)
at
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThrea
d.java:184)
at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:178)
at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:170)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)




0
Comment actions Permalink

Maxim

-Xbootclasspath/p:$/lib/boot.jar



There were spaces in the path and app name.
I removed them, and it works fine now.


Alain

0
Comment actions Permalink

Is there a plug-in available, which uses the com.intellij.testFramework,
so I can see, how it works? Thanks in advance.

Tom

0
Comment actions Permalink

No such plug-in available?

Tom

0
Comment actions Permalink

Tom

No such plug-in available?

>

I think Dave's Rearranger plugin test code uses the openAPI test framework.

Alain

0
Comment actions Permalink

I've tried to run a test with the built-in JUnit-tester, but get the
following error:

Extension implementation class not found:
org.jetbrains.idea.devkit.run.JUnitDevKitPatcher
ERROR:
com.intellij.diagnostic.PluginException:
com.siyeh.ig.InspectionGadgetsPlugin
at
com.intellij.openapi.components.impl.ComponentManagerImpl.loadComponentsConfiguration(ComponentManagerImpl.java:224)
at
com.intellij.openapi.application.impl.ApplicationImpl.c(ApplicationImpl.java:315)
at
com.intellij.openapi.application.impl.ApplicationImpl.(ApplicationImpl.java:169) at com.intellij.openapi.application.ex.ApplicationManagerEx.createApplication(ApplicationManagerEx.java:5) at com.intellij.idea.CommandLineApplication.(CommandLineApplication.java:17) at com.intellij.idea.CommandLineApplication.(CommandLineApplication.java:6) at com.intellij.idea.IdeaTestApplication.]]>(IdeaTestApplication.java:5)
at
com.intellij.idea.IdeaTestApplication.getInstance(IdeaTestApplication.java:4)
at com.intellij.testFramework.LightIdeaTestCase.a(LightIdeaTestCase.java:5)
at
com.intellij.testFramework.LightIdeaTestCase.setUp(LightIdeaTestCase.java:77)
at com.wrq.rearranger.RearrangerTest.setUp(RearrangerTest.java:41)
at com.intellij.testFramework.LightIdeaTestCase.d(LightIdeaTestCase.java:44)
at
com.intellij.testFramework.LightIdeaTestCase.access$400(LightIdeaTestCase.java:80)
at com.intellij.testFramework.LightIdeaTestCase$4.run(LightIdeaTestCase.java:2)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:199)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
at
java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
at
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

Does anybody know how to solve it? Thanks in advance.

Tom

0

Please sign in to leave a comment.