JUnit 4.8需要什么java版本 [英] What java version is needed for JUnit 4.8

查看:145
本文介绍了JUnit 4.8需要什么java版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用1.5 JRE运行JUnit测试,但是收到错误消息:

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

当我切换到JRE 1.6(实际上是一个JDK,但这不重要,对吗?)时,每件事都可以。

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

所以问题是:


  • 我们真的需要Java 6用于当前的JUnit版本吗?

  • 什么是最新的JUnit版本,适用于Java 5?

推荐答案

几个类的抽查显示 JUnit 4.8.2 jar文件是用java 5编译的,或者用java 6编译器编译的 -target 选项设置使它与java5兼容的类文件。

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.

更有可能的解释是你已经意外地编译了您想要使用Java 6 JDK运行的测试。是什么:

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

在主要版本的输出顶部说?如果它说 50 ,那么问题是你只编译了java 6的测试类。您需要使用JDK 5编译器或将选项 -target 1.5 传递给编译器。

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.

这篇关于JUnit 4.8需要什么java版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆