[java] Eclipse and JUnit

Started by
8 comments, last by ToohrVyk 16 years, 10 months ago
I'm having trouble running JUnit from Eclipse. I have generated a simple test case, ValueTest, using the Eclipse built-in wizard and included tests for three methods of an existing Value class. I left the methods unimplemented (so they fail("Not yet implemented");), and chose Run > Run As > JUnit Test from the menus. A "JUnit" panel appeared on the left side of the IDE, and showed "Launching ValueTest". After waiting a few minutes, the console panel shows:
ERROR: transport error 202: connect failed: Connection timed out
ERROR: JDWP Transport dt_socket failed to initialize, TRANSPORT_INIT(510)
JDWP exit error AGENT_ERROR_TRANSPORT_INIT(197): No transports initialized
FATAL ERROR in native method: JDWP No transports initialized, jvmtiError=AGENT_ERROR_TRANSPORT_INIT(197)
I can run JUnit independently without problem:
arkadir@nyarlathotep /home/arkadir/workspace/weirs/bin
> junit time.ValueTest
.F.F.F
Time: 0.005
There were 3 failures:
(...)
I'm running the Java 6 JRE on a Debian Linux, and a freshly installed Eclipse. Any ideas about where the problem is from?
Advertisement
One thing I'd check is whether the JDK that runs eclipse is the same as the one that launches the application.

It's not impossible that eclipse launches a different one.

Other than that, this seems to be a frequent problem with 1.6, with no real solution. Could also be a bug in JVM.
is your firewall blocking localhost connections?
I am not aware of any firewall running on my machine. I'll try to find a tool to check which ports are open.

I've tried changing the JRE (more details on this in a few hours), but I haven't sorted out all the details yet (I still have to remove the older JRE).
As an attempt to solve my JUnit problem, I've uninstalled the Java5 and Java6 JREs from my computer, and installed the GCJ JRE. This has had the funny consequence of completely screwing up Eclipse. This happens when running an Eclipse-built class from either Eclipse or using command-line java (or junit, for :

Exception in thread "main" java.lang.ClassFormatError: Entry (unrecognized class file version)   at java.lang.VMClassLoader.defineClass(libgcj.so.70)   at java.lang.ClassLoader.defineClass(libgcj.so.70)   at java.security.SecureClassLoader.defineClass(libgcj.so.70)   at java.net.URLClassLoader.findClass(libgcj.so.70)   at gnu.gcj.runtime.SystemClassLoader.findClass(libgcj.so.70)   at java.lang.ClassLoader.loadClass(libgcj.so.70)   at java.lang.ClassLoader.loadClass(libgcj.so.70)   at gnu.java.lang.MainThread.run(libgcj.so.70)


However, I notice that compiling programs with command-line javac and then running them with java or Eclipse, works without any apparent problem. A quick comparison of files generated by Eclipse on the one hand and javac on the other hand yield:

bin/Correct.class:    compiled Java class data, version 46.0bin/Incorrect.class:  compiled Java class data, version 50.0


So, it does appear that there's a version difference. However, the only JRE I find in the Eclipse properties or the eclipse properties is the GCJ one. Actually, it's the only JRE (and compiler) available on my system:

/usr/bin/javac/usr/lib/jvm/java-1.4.2-gcj-4.1-1.4.2.0/bin/javac/usr/lib/jvm/java-1.4.2-gcj-4.1-1.4.2.0/man/man1/javac.1.gz


Which means that Eclipse is somehow using the GCJ javac to generate an output which is incompatible with command line use of javac, and also incompatible with the entire GCJ virtual machine!

I'm a bit lost here... Any simple way of bonking Eclipse on the head, so that it uses javac correctly? Any places where I might have screwed up and asked for an incorrect file version?
Doesn't the version number correspond to the JVM spec it's for? A quick poke around the internet suggests that version 46.0 is JDK 1.2, and 50.0 is JDK 1.6.

I'd suggest uninstalling GCJ, as it's not particularly good and lags somewhat behind the current version. IIRC Eclipse uses it's own internal compiler, you can set the target JRE version in the workspace settings (or override it in the per-project settings).

At a guess, Eclipse is internally compiling 1.6 classfiles and you're trying to run them via the GCJ runtime, which is only expecting 1.2 for some reason (is that as high as it goes?).
Quote:I'm a bit lost here... Any simple way of bonking Eclipse on the head, so that it uses javac correctly? Any places where I might have screwed up and asked for an incorrect file version?


I'll assume you set up the JDK and JRE versions properly (JDK is the preferred version for eclipse) in the options.

In addition, the same options allow you to set for which version to compile.

Due to changes between 1.3 - 1.6 (adding assert as keyword, generics et al), there's quite some confusion and some enforcement of version done by eclipse.

I'm using eclipse 3.2 with jdk 1.5 (haven't switch yet to 1.6).

Under Window/Preferences/Java/Compiler there's all the relevant (and all possible) settings. Under some circumstances eclipse can force the some weird compatibility settings which aren't necessary.

Additionally, under ../Java/Installed JREs you should double check that the proper JRE is getting installed. Eclipse has a preference of using JRE, instead of JDK.

Another thing to check is the ../Java/Build Path/Classpath Variables. Eclipse comes with its own, pre-built JUnit classes. Those could be a problem.
I've uninstalled GCJ, and installed java5-jdk. Eclipse compilation now works correctly, but JUnit (launched from Eclipse) still fails (this time, no error message, it just displays "Loading tests" forever.

I don't see the point in pushing any further my attempts to get JUnit and Eclipse to work together: I spent two minutes writing a script to run the tests using /bin/sh and command-line junit instead; if spending another week fiddling with Eclipse is the price to pay for Eclipse-JUnit integration, I seriously doubt it's worth the effort.

Thank you everyone for your input in this thread, even if it didn't turn out well in the end.
What build/version of Eclipse are you using? If you're using a nightly build then it could just be that the functionality is broken. You might want to try a stable build if you're not already using one of those.
Quote:Original post by OrangyTang
What build/version of Eclipse are you using? If you're using a nightly build then it could just be that the functionality is broken. You might want to try a stable build if you're not already using one of those.


I'm using the version provided in Debian-unstable (so that's the September 21, 2006 one).

This topic is closed to new replies.

Advertisement