我正在尝试实现一个 JUnit 测试来测试一个演员。
我有这个 ActorTest :
import org.junit.Test;
import play.libs.Akka;
import playtests.PlayFrameworkTest;
import akka.actor.Actor;
import akka.actor.Props;
import akka.actor.UntypedActorFactory;
import akka.testkit.TestActorRef;
public class ActorTest {
public static FakeApplication dummy;
@BeforeClass
public static void startApp() {
dummy = Helpers.fakeApplication(Helpers.inMemoryDatabase());
Helpers.start(dummy);
}
@AfterClass
public static void stopApp() {
Helpers.stop(dummy);
}
@Test
public void test() throws Exception {
final String myParameter = "someParameter";
@SuppressWarnings("serial")
TestActorRef<MyActor> actorRef = TestActorRef.create(Akka.system(), new Props(new UntypedActorFactory() {
@Override
public Actor create() {
return new MyActor(myParameter);
}
}), "testActor");
MyActor actor = actorRef.underlyingActor();
String message = "message";
actor.apply(message);
actor.receive();
}
}
当我尝试运行它时(无论是在 eclipse 上还是使用“play test”命令行),我都会在 TestActorRef.create() 的行中抛出这个异常
java.lang.NoClassDefFoundError: scala/concurrent/duration/Duration
at persistence.actors.ActorTest.test(ActorTest.java:45)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.ClassNotFoundException: scala.concurrent.duration.Duration
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 26 more
我看过http://doc.akka.io/docs/akka/snapshot/java/testing.html 和 http://doc.akka.io/docs/akka/snapshot/scala/testing.html 和所有我能在播放框架页面上找到。
我错过了什么?为什么它不运行?如果我从 Akka.system() 和 ActorSystem.apply() 获取我的系统,我会得到同样的异常......当我将它传递给我的 fakeApplication 时,同样的事情。