JUnit在play framework 2.0.4中测试Akka actor - 在scala.concurrent.duration.Duration上的JAVA ClassNotFoundException

时间:2013-02-28 17:59:29

标签: java playframework playframework-2.0 junit4 akka

我正在尝试实现一个JUnit测试来测试一个actor。

我有这个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.htmlhttp://doc.akka.io/docs/akka/snapshot/scala/testing.html 我可以在播放框架页面上找到所有内容。

我错过了什么?为什么不运行?如果我从Akka.system()和ActorSystem.apply()获取我的系统,我会得到相同的异常...当我传递我的假应用程序时,我也会这样做。

1 个答案:

答案 0 :(得分:1)

(总结上面的评论......)类scala.concurrent.duration.Duration最初包含在Scala 2.10中。在撰写本文时,Akka 2.1和Play 2.1是使用Scala 2.10的最佳版本。