Play Framework(2.1.3)不运行任何测试

时间:2013-08-16 14:26:10

标签: java junit playframework

我有4个测试类,每个测试类平均有两个测试函数。第一个测试在下面,必须是正确的(来自Play的教程)。

public class ApplicationTest {

    @Test 
    public void simpleCheck() {
        int a = 1 + 1;
        assertThat(a).isEqualTo(2);
    }

}

其他的是自定义的,并设置@Before,如下所示:

public class UserTest extends WithApplication {

@Before
public void setUp() {
    start(fakeApplication(inMemoryDatabase()));
}

// creation and retrieval of user
@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);                 // successfully retrieved
    assertEquals("Bob", bob.getName()); // correct user retrieved
}
}

现在,当我运行play test时,它会更快完成并且不会执行任何测试。

PS C:\wamp\www\dcid> play test
[info] Loading project definition from C:\wamp\www\dcid\project
[info] Set current project to dcid (in build file:/C:/wamp/www/dcid/)
[info] Compiling 4 Java sources to C:\wamp\www\dcid\target\scala-2.10\test-classes...
[info] ApplicationTest
[info]
[info]
[info] Total for test ApplicationTest
[info] Finished in 0.014 seconds
[info] 0 tests, 0 failures, 0 errors
[info] models.UserTest
[info]
[info]
[info] Total for test models.UserTest
[info] Finished in 0.002 seconds
[info] 0 tests, 0 failures, 0 errors
[info] models.ProposalTest
[info]
[info]
[info] Total for test models.ProposalTest
[info] Finished in 0.002 seconds
[info] 0 tests, 0 failures, 0 errors
[info] Passed: : Total 0, Failed 0, Errors 0, Passed 0, Skipped 0
[success] Total time: 5 s, completed 16/Ago/2013 14:52:35

这是为什么?我该怎么办? 我最近从播放2.1.2更新到2.1.3。我更新了所有引用,项目工作正常,除了测试。 我也looked at this question,但不是那样,因为我没有改变我的测试,所以写得很好,只是他们的执行不起作用。

1 个答案:

答案 0 :(得分:14)

这是a known issue of Play 2.1.3。同时有a workaround。 将以下内容添加到val main函数中的Build.scala文件中:

val main = play.Project(appName, appVersion, appDependencies).settings(
  // Add your own project settings here      
  testOptions in Test ~= { args =>
    for {
      arg <- args
      val ta: Tests.Argument = arg.asInstanceOf[Tests.Argument]
      val newArg = if(ta.framework == Some(TestFrameworks.JUnit)) ta.copy(args = List.empty[String]) else ta
    } yield newArg
  }
)