运行以下代码段(在 Eclipse 中设置 JDK 7):
import javafx.scene.Scene;
import javafx.stage.Stage;
import org.junit.Test;
import org.testfx.framework.junit.ApplicationTest;
public class BasicTestFxTest extends ApplicationTest
{
@Override
public void start(Stage stage) throws Exception
{
Scene scene = new Scene(null, 800, 600);
stage.setScene(scene);
stage.show();
}
@Test
public void test()
{
System.out.println("This is not a test.");
}
}
导致以下异常:
java.lang.UnsupportedClassVersionError: org/testfx/framework/junit/ApplicationTest : java.lang.ClassLoader.defineClass1(Native Method) at java.security 的 java.lang.ClassLoader.defineClass(Unknown Source) 不支持 major.minor 版本 52.0 .SecureClassLoader.defineClass(Unknown Source) at java.net.URLClassLoader.defineClass(Unknown Source) at java.net.URLClassLoader.access$100(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source) at java.net .URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc。 Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang。ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(Unknown Source) at java.security.SecureClassLoader.defineClass(Unknown Source) at java.net.URLClassLoader.defineClass(Unknown Source) at java.net.URLClassLoader。 access$100(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader .findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at org.eclipse.jdt .internal.junit.runner.RemoteTestRunner.loadClass(RemoteTestRunner.java:685) 在 org.eclipse.jdt.internal.junit.runner。RemoteTestRunner.loadClasses(RemoteTestRunner.java:421) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:444) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests( RemoteTestRunner.java:675) 在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) 在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java: 192)主要(RemoteTestRunner.java:192)主要(RemoteTestRunner.java:192)
注意:我使用的是 testfx-core 和 testfx-junit 4.0.1-alpha。