Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What java version is needed for JUnit 4.8

I am trying to run JUnit test with a 1.5 JRE, but get the error Message:

java.lang.UnsupportedClassVersionError: Bad version number in .class file

When I switch to JRE 1.6 (actually a JDK but that shouldn't matter, right?) everythings works fine.

So the questions are:

  • Do we really need Java 6 for the current JUnit version?
  • what is the newest JUnit version, that works with Java 5?
like image 330
Jens Schauder Avatar asked Apr 29 '10 13:04

Jens Schauder


People also ask

Does JUnit 5 work with Java 7?

JUnit 5 requires Java 8 (or higher) at runtime.

Does JUnit 4 support java8?

JUNIT4 doesn't work under java 8.

Is JUnit 4 still supported?

The platform changes in a highly incompatible way and the Vintage engine will no longer be supported. This is not to be expected in the near future.


2 Answers

A spot check of a few classes shows that the JUnit 4.8.2 jar file was compiled with java 5, or with the java 6 compiler with the -target option set so that it makes java5-compatible class files.

A far more likelier explanation is that you've accidentally compiled the test you wanted to run with a Java 6 JDK. What does:

javap -verbose -classpath YOUR_TOP_DIRECTORY com.yourname.YourTest

say at the top of its output for "major version"? If it says 50, then the problem is that you've compiled your test class for java 6 only. You need to either use a JDK 5 compiler or pass the option -target 1.5 to your compiler.

like image 198
Daniel Martin Avatar answered Sep 19 '22 11:09

Daniel Martin


The current .jar file for JUnit 4.8.2 was compiled with/for Java 5 (class version number is 49.0).

I remember an earlier version accidentally being built with Java 6 (and without the -target switch), but that was simply a mistake.

like image 28
Joachim Sauer Avatar answered Sep 18 '22 11:09

Joachim Sauer