[ANN] JUnitTestPlugin 0.14 available

http://www.intellij.org/twiki/bin/view/Main/JUnitTestPlugin

  • Change settings to go to the workspace instead. This makes sharing the project file easier.

  • Add test class velocity template generation

  • Fix the intermittent assertion in isUnitTest() (reported by Bas Leijdekkers & Debabrata Dash)

  • Migrated to 873


Special thanks to Bronwen Cassidy that did most of the template generation implementation

11 comments
Comment actions Permalink

Hmm... Ctrl-T has gone away...

0
Comment actions Permalink

Aaah. Ctrl-Shift-T is the winner... :)

0
Comment actions Permalink

Great! Excellent plugin!
I do have a bug to report however:-) Even my tested methods now have an
icon in the gutter. I thought only untested methods got an icon?

Bas

0
Comment actions Permalink

Is your class pattern correct?
Do you navigate to the right test class when you hit Ctrl-Shit-T? Do you go to a different class when you click on the icon?
Also try to go to one of the test method you already have and hit Ctrl-Shift-T. Does it go back to the method under test? Do it again. Does it go back to the same test method?

Jacques

0
Comment actions Permalink

Hmm, JUnitTestPlugin doesn't work correctly in one of my projects. If I
press CtrlShiftT in a method of a class that doesn't have a
corresponding test class yet, it offers to create it. After that a file
is created, but the contents of that file are not correct. The class
name is not expanded:

public class $Test extends TestCase.

Also the focus is not transfered to that file and the test method is not
created. Pressing CtrlShiftT again produces the exception below.
When I try it in an other project everything works as expected. I don't
know what the difference between the projects is to cause this behaviour.

2003-07-28 16:55:46,792 ERROR -
t.actions.JUnitTestCaseHandler -
2003-07-28 16:55:46,812 ERROR -
t.actions.JUnitTestCaseHandler - IntelliJ IDEA (Aurora) Build #873
2003-07-28 16:55:46,812 ERROR -
t.actions.JUnitTestCaseHandler - JDK: 1.4.2
2003-07-28 16:55:46,812 ERROR -
t.actions.JUnitTestCaseHandler - VM: Java HotSpot(TM) Client VM
2003-07-28 16:55:46,812 ERROR -
t.actions.JUnitTestCaseHandler - Vendor: Sun Microsystems Inc.
2003-07-28 16:55:46,812 ERROR -
t.actions.JUnitTestCaseHandler - OS: Windows 2000
2003-07-28 16:55:46,812 ERROR -
t.actions.JUnitTestCaseHandler - Last Action:
JUnitTestPlugin.ToggleTestCaseTestedClassAction
2003-07-28 16:55:46,812 ERROR -
t.actions.JUnitTestCaseHandler -
com.intellij.util.IncorrectOperationException: Cannot create file - file
"E:\Projects\carpcode\tst\com\carp\pos\postprocessor\PostProcessorTest.java"
already exists.
at com.intellij.psi.impl.a.d.checkCreateFile(d.java:236)
at com.intellij.psi.impl.a.d.createFile(d.java:170)
at
org.intellij.plugins.util.PsiClassManager.createClass(PsiClassManager.java:91)
at
org.intellij.plugins.util.PsiClassManager.createPrimaryClassFromTemplate(PsiClassManager.java:73)
at
org.intellij.plugins.junit.ClassLocator.createTestClass(ClassLocator.java:31)
at
org.intellij.plugins.junit.actions.GoToUnitTestHandler.createTestClass(GoToUnitTestHandler.java:149)
at
org.intellij.plugins.junit.actions.GoToUnitTestHandler.access$000(GoToUnitTestHandler.java:29)
at
org.intellij.plugins.junit.actions.GoToUnitTestHandler$CreateTestClassCommand.run(GoToUnitTestHandler.java:79)
at org.intellij.plugins.util.CommandUtil$4.run(CommandUtil.java:80)
at com.intellij.openapi.application.b.d.runWriteAction(d.java:248)
at org.intellij.plugins.util.CommandUtil.runAction(CommandUtil.java:87)
at org.intellij.plugins.util.CommandUtil.access$100(CommandUtil.java:13)
at org.intellij.plugins.util.CommandUtil$3.run(CommandUtil.java:70)
at com.intellij.openapi.command.b.b.executeCommand(b.java:44)
at
org.intellij.plugins.util.CommandUtil.executeCommand(CommandUtil.java:68)
at
org.intellij.plugins.util.CommandUtil.executeWriteCommand(CommandUtil.java:25)
at
org.intellij.plugins.junit.actions.GoToUnitTestHandler.findOrCreateTestClass(GoToUnitTestHandler.java:89)
at
org.intellij.plugins.junit.actions.GoToUnitTestHandler.execute(GoToUnitTestHandler.java:48)
at
org.intellij.plugins.junit.actions.ToggleTestCaseTestedClassAction.actionPerformed(ToggleTestCaseTestedClassAction.java:57)
at com.intellij.openapi.a.b.e.a(e.java:68)
at com.intellij.openapi.a.b.e.b(e.java:150)
at com.intellij.openapi.a.b.e.a(e.java:115)
at com.intellij.ide.s.dispatchEvent(s.java:114)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

Regards,
Bas

0
Comment actions Permalink

Jacques Morel wrote:

Is your class pattern correct?


I think it is. I use the following pattern:
Tested Class src/$PACKAGE$/$CLASS$
Test Class tst/$PACKAGE$/$CLASS$Test

Do you navigate to the right test class when you hit Ctrl-Shit-T?


Yes.

Do you go to a different class when you click on the icon?


No

Also try to go to one of the test method you already have and hit Ctrl-Shift-T. Does it go back to the method under test? Do it again.

Does it go back to the same test method?

Yes.
The problem also seems to be temporary. After restarting IDEA or closing
and opening the project only untested methods have the icon.

I have now found some more information about the problem. It has
something to do with the pattern settings. When I change the pattern
e.g. change the Test Class pattern to
"nonexistant/$PACKAGE$/$CLASS$Test", I expect all my methods to get
icons. The setting is not fully changed untill the project is reloaded.

Hope this helps,
Bas

0
Comment actions Permalink

To reproduce:
1. Click on the "..." button in "Project Properties/JUnit/Options/"
2. Cancel the Open dialog.

Regards,
Bas


2003-07-28 17:48:23,732 ERROR -
com.intellij.ide.IdeEventQueue - Error during dispatching of
java.awt.event.MouseEvent[MOUSE_RELEASED,(665,112),button=1,modifiers=Button1,clickCount=1]
on dialog0
2003-07-28 17:48:23,752 ERROR -
com.intellij.ide.IdeEventQueue - IntelliJ IDEA (Aurora) Build #873
2003-07-28 17:48:23,752 ERROR -
com.intellij.ide.IdeEventQueue - JDK: 1.4.2
2003-07-28 17:48:23,752 ERROR -
com.intellij.ide.IdeEventQueue - VM: Java HotSpot(TM) Client VM
2003-07-28 17:48:23,752 ERROR -
com.intellij.ide.IdeEventQueue - Vendor: Sun Microsystems Inc.
2003-07-28 17:48:23,752 ERROR -
com.intellij.ide.IdeEventQueue - OS: Windows 2000
2003-07-28 17:48:23,762 ERROR -
com.intellij.ide.IdeEventQueue -
java.lang.NullPointerException
at
org.intellij.plugins.ui.RelativeFilePathField$1.actionPerformed(RelativeFilePathField.java:56)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at
javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(Unknown
Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at com.intellij.ide.s.a(s.java:15)
at com.intellij.ide.s.dispatchEvent(s.java:74)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.Dialog$1.run(Unknown Source)
at java.awt.Dialog.show(Unknown Source)
at
com.intellij.openapi.ui.DialogWrapper$MyDialog.show(DialogWrapper.java:36)
at com.intellij.openapi.ui.DialogWrapper.show(DialogWrapper.java:27)
at com.intellij.ide.q.dv.actionPerformed(dv.java:0)
at com.intellij.openapi.actionSystem.a.y.a(y.java:67)
at com.intellij.openapi.actionSystem.a.y.processMouseEvent(y.java:69)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at com.intellij.ide.s.a(s.java:15)
at com.intellij.ide.s.dispatchEvent(s.java:74)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

0
Comment actions Permalink

I found the problem.
Use CLASS_NAME instead of CLASSNAME or NAME (as mentioned in the docs).
We will change this in the next version to follow the IDEA variable name (NAME)

Sorry for the confusion and let me know if it works.

Jacques

0
Comment actions Permalink

Jacques Morel wrote:

I found the problem.
Use CLASS_NAME instead of CLASSNAME or NAME (as mentioned in the docs).
We will change this in the next version to follow the IDEA variable name (NAME)


Yes, that was it! I should have read the docs:-) When I saw the option
of using a template I just selected my own TestCase template I had been
using, thinking I would get a warning if something was wrong with it.
After adjusting my template it looks like everything is working great!

Thanks,
Bas

p.s. I did get one other exception, but I could fix that by adjusting
the template (wrong line separators):

2003-07-29 12:05:01,775 ERROR -
enapi.editor.impl.DocumentImpl - Assertion failed: Wrong line separators
inserted into Document
2003-07-29 12:05:01,925 ERROR -
enapi.editor.impl.DocumentImpl - IntelliJ IDEA (Aurora) Build #873
2003-07-29 12:05:01,925 ERROR -
enapi.editor.impl.DocumentImpl - JDK: 1.4.2
2003-07-29 12:05:01,925 ERROR -
enapi.editor.impl.DocumentImpl - VM: Java HotSpot(TM) Client VM
2003-07-29 12:05:01,925 ERROR -
enapi.editor.impl.DocumentImpl - Vendor: Sun Microsystems Inc.
2003-07-29 12:05:01,925 ERROR -
enapi.editor.impl.DocumentImpl - OS: Windows 2000
2003-07-29 12:05:01,925 ERROR -
enapi.editor.impl.DocumentImpl - Last Action:
JUnitTestPlugin.ToggleTestCaseTestedClassAction
2003-07-29 12:05:01,925 ERROR -
enapi.editor.impl.DocumentImpl - Current Command: Create Test Class
E:/Projects/carpcode/tst/com/carp/pos/postprocessor/QuantifierPostProcessorTest.java

2003-07-29 12:05:01,945 ERROR -
enapi.editor.impl.DocumentImpl -
java.lang.Throwable
at com.intellij.openapi.diagnostic.Logger.assertTrue(Logger.java:9)
at com.intellij.openapi.editor.d.p.insertString(p.java:175)
at
org.intellij.plugins.util.PsiClassManager.createClass(PsiClassManager.java:94)
at
org.intellij.plugins.util.PsiClassManager.createPrimaryClassFromTemplate(PsiClassManager.java:73)
at
org.intellij.plugins.junit.ClassLocator.createTestClass(ClassLocator.java:31)
at
org.intellij.plugins.junit.actions.GoToUnitTestHandler.createTestClass(GoToUnitTestHandler.java:149)
at
org.intellij.plugins.junit.actions.GoToUnitTestHandler.access$000(GoToUnitTestHandler.java:29)
at
org.intellij.plugins.junit.actions.GoToUnitTestHandler$CreateTestClassCommand.run(GoToUnitTestHandler.java:79)
at org.intellij.plugins.util.CommandUtil$4.run(CommandUtil.java:80)
at com.intellij.openapi.application.b.d.runWriteAction(d.java:248)
at org.intellij.plugins.util.CommandUtil.runAction(CommandUtil.java:87)
at org.intellij.plugins.util.CommandUtil.access$100(CommandUtil.java:13)
at org.intellij.plugins.util.CommandUtil$3.run(CommandUtil.java:70)
at com.intellij.openapi.command.b.b.executeCommand(b.java:44)
at
org.intellij.plugins.util.CommandUtil.executeCommand(CommandUtil.java:68)
at
org.intellij.plugins.util.CommandUtil.executeWriteCommand(CommandUtil.java:25)
at
org.intellij.plugins.junit.actions.GoToUnitTestHandler.findOrCreateTestClass(GoToUnitTestHandler.java:89)
at
org.intellij.plugins.junit.actions.GoToUnitTestHandler.execute(GoToUnitTestHandler.java:48)
at
org.intellij.plugins.junit.actions.ToggleTestCaseTestedClassAction.actionPerformed(ToggleTestCaseTestedClassAction.java:57)
at com.intellij.openapi.a.b.e.a(e.java:68)
at com.intellij.openapi.a.b.e.b(e.java:150)
at com.intellij.openapi.a.b.e.a(e.java:115)
at com.intellij.ide.s.dispatchEvent(s.java:114)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

0
Comment actions Permalink

Any way to setup multiple patterns?

My project setup (j2ee.ear) are as follows:
j2ee.ear/web-app/WEB-INF/classes/com/...
j2ee.ear/ejb-app1/com/...
j2ee.ear/ejb-1pp2/com/...

<!--
web-app
-->
Tested Class j2ee.ear/web-app/WEB-INF/classes$PACKAGE$/$CLASS$
Test Class j2ee.ear.test/web-app/WEB-INF/classes/$PACKAGE$/$CLASS$Test

<!--
ejb apps
-->
Tested Class j2ee.ear/$PACKAGE$/$CLASS$
Test Class j2ee.ear.test/$PACKAGE$/$CLASS$Test

Thanks in advance!

Chris

0
Comment actions Permalink

You are the unfortunate victim of a bad choice of variable name. PACKAGE does not just match packages but also directories.
This has been discussed before but I completely forgot to change it. It will do that in the next release.

So as long as everything tested class is under j2ee.ear and every test class is under j2ee.ear.test with the same directory structure underneath you can just use
Tested class j2ee.ear/$PACKAGE$/$CLASS$Test
Test class j2ee.ear.test/$PACKAGE$/$CLASS$Test

It should work.

Let me know if it doesn't. Multi-pattern support is in the plan but I do not know when.

Jacques

0

Please sign in to leave a comment.