播放框架 - 错误:包org.junit不存在

时间:2013-11-12 17:34:27

标签: java playframework playframework-2.0

当我尝试测试应用程序时(通过以下this教程制作)我得到以下错误

[info] Compiling 1 Java source to C:\Users\Xyzk\zentask\target\scala-2.10\classes...
[error] C:\Users\Xyzk\zentask\app\models\ModelsTest.java:4: error: package org.junit does not exist
[error] import org.junit.*;
[error] ^
[error] C:\Users\Xyzk\zentask\app\models\ModelsTest.java:5: error: package org.junit does not exist
[error] import static org.junit.Assert.*;
[error]                        ^
[error] C:\Users\Xyzk\zentask\app\models\ModelsTest.java:6: error: package play.test does not exist
[error] import play.test.WithApplication;
[error]                 ^
[error] C:\Users\Xyzk\zentask\app\models\ModelsTest.java:7: error: package play.test does not exist
[error] import static play.test.Helpers.*;
[error]                        ^
[error] C:\Users\Xyzk\zentask\app\models\ModelsTest.java:9: error: cannot find symbol
[error] public class ModelsTest extends WithApplication {
[error]                                 ^
[error]   symbol: class WithApplication
[error] C:\Users\Xyzk\zentask\app\models\ModelsTest.java:10: error: cannot find symbol
[error]     @Before
[error]      ^
[error]   symbol:   class Before
[error]   location: class ModelsTest
[error] C:\Users\Xyzk\zentask\app\models\ModelsTest.java:12: error: cannot find symbol
[error]         start(fakeApplication(inMemoryDatabase()));
[error]                               ^
[error]   symbol:   method inMemoryDatabase()
[error]   location: class ModelsTest
[error] 7 errors
[error] (compile:compile) javac returned nonzero exit code

怎么能检测不到标准库?我的ModelsTest.java

package models;
import models.*;
import org.junit.*;
import static org.junit.Assert.*;
import play.test.WithApplication;
import static play.test.Helpers.*;

public class ModelsTest extends WithApplication {
@Before
public void setUp() {
    start(fakeApplication(inMemoryDatabase()));
}

@Test
public void createAndRetrieveUser() {
    new User("bob@gmail.com", "Bob", "secret").save();
    User bob = User.find.where().eq("email", "bob@gmail.com").findUnique();
    assertNotNull(bob);
    assertEquals("Bob", bob.name);
}
}

1 个答案:

答案 0 :(得分:5)

我在Play邮件列表中找到了解决方案。我想你将ModelsTest.java放在app中。您需要将其放在test中,而不是app