IDEA seems to hate JUnit

I'm trying to use JUnit with IDEA build 1182, but I can't get it to work. I have this project, with a single module containing just 4 classes. I added the junit.jar file found under the IDEA lib dir. I created a test that imports junit.framework.TestCase, but IDEA complainted that it can't resolve TestCase. So I tried to download junit myself, and added this jar file to the classpath, but it didn't work. Finally I extracted the junit sourcecode under the module directory, and finally it was able to resolve TestCase.

If I try to browse junit.jar in the Project view, I just get a lot of unnamed Class entries in all of the packages. This happens even if I attached the src.jar to the junit.jar file in an attempt to help IDEA.

Also, when I try to run the Edit Configurations->JUnit, I get an error saying "JUnit not found in module ]]>".

I should also mention that I was able to compile my file import TestCase, it was just the editor that didn't seem to understand anything.

6 comments
Comment actions Permalink

? wrote:

I'm trying to use JUnit with IDEA build 1182, but I can't get it to work. I have this project, with a single module containing just 4 classes. I added the junit.jar file found under the IDEA lib dir. I created a test that imports junit.framework.TestCase, but IDEA complainted that it can't resolve TestCase. So I tried to download junit myself, and added this jar file to the classpath, but it didn't work. Finally I extracted the junit sourcecode under the module directory, and finally it was able to resolve TestCase.

If I try to browse junit.jar in the Project view, I just get a lot of unnamed Class entries in all of the packages. This happens even if I attached the src.jar to the junit.jar file in an attempt to help IDEA.

Also, when I try to run the Edit Configurations->JUnit, I get an error saying "JUnit not found in module <MyModule>".

I should also mention that I was able to compile my file import TestCase, it was just the editor that didn't seem to understand anything.

No need to do all this. Just go to Settings -> Paths, select your
module, go to Libraries tab, and add the JUnit jar to Module libraries.
It's probably best to use your own copy of junit.jar so that you have
control over it, but I guess using the one from IDEA installation
probably works okay.

--
Rob Harwood
Software Developer
JetBrains Inc.
http://www.jetbrains.com
"Develop with pleasure!"

0
Comment actions Permalink

The problem I get is that when a run a unit test idea says Class not found "com.babel17.spring.DumbTest" even though the class is present - derives from Testcase and does nothing interesting. I get this behavior whether I use junit.jar from Idea's lib or the original sources and for all projects!! it started a week or so ago after I installed build 2192 of 4.5 bit affects 4.0 and 4.5 installations - I am tearing my hair because no unit tests work in debug or run mode and I have No idea as to why.

0
Comment actions Permalink

lordjoe wrote:

>The problem I get is that when a run a unit test idea says Class not found "com.babel17.spring.DumbTest" even though the class is present - derives from Testcase and does nothing interesting. I get this behavior whether I use junit.jar from Idea's lib or the original sources and for all projects!! it started a week or so ago after I installed build 2192 of 4.5 bit affects 4.0 and 4.5 installations - I am tearing my hair because no unit tests work in debug or run mode and I have No idea as to why.

>
They don't auto compille - hit compile then run ( annoying but works )

0
Comment actions Permalink

Go to "Edit Configurations..." and check off "make module before run..." for the test case

0
Comment actions Permalink

I seem to be experiencing the same problem as lordjoe even after trying what was suggested. I'm using 4.5 Build #2233, this worked in 4.0.3.

0
Comment actions Permalink

Sorry, I found my problem. I had JUnit in Sun's jre/lib/ext dir. When I removed it from that directory and restarted Idea the unit tests worked fine.

0

Please sign in to leave a comment.