Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have 4 test classes with an average of two test functions each. The first test is below and must be correct (its from Play's tutorial).

public class ApplicationTest {

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

}

The other ones are custom made and have a @Before setup, like this:

public class UserTest extends WithApplication {

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

// creation and retrieval of user
@Test
public void createAndRetrieveUser() {
    new User("[email protected]", "Bob", "secret").save();

    User bob = User.find.where().eq("email", "[email protected]").findUnique();

    assertNotNull(bob);                 // successfully retrieved
    assertEquals("Bob", bob.getName()); // correct user retrieved
}
}

Now when I run play test it finishes a lot quicker and doesn't execute any test.

PS C:wampwwwdcid> play test
[info] Loading project definition from C:wampwwwdcidproject
[info] Set current project to dcid (in build file:/C:/wamp/www/dcid/)
[info] Compiling 4 Java sources to C:wampwwwdcidargetscala-2.10est-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

Why is this? What can I do? I recently updated from play 2.1.2 to 2.1.3. I updated all references and the project is working fine, except the tests. I also looked at this question, but it can't be that, since I didn't change my tests, so they are well written, it's just their execution that is not working.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
238 views
Welcome To Ask or Share your Answers For Others

1 Answer

It's a known issue of Play 2.1.3. Meanwhile there is a workaround. Add the following into Build.scala file in the val main function:

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
  }
)   

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...