2013-08-16 18 views
11

Tôi có 4 lớp thử nghiệm với trung bình hai hàm kiểm tra. Bài kiểm tra đầu tiên ở dưới và phải chính xác (từ bài hướng dẫn của Play).Play Framework (2.1.3) không chạy bất kỳ thử nghiệm nào

public class ApplicationTest { 

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

} 

Những người khác được tùy chỉnh thực hiện và có thiết lập @Before, như thế này:

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

Bây giờ khi tôi chạy play test nó kết thúc nhanh hơn rất nhiều và không thực hiện bất kỳ thử nghiệm.

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 

Tại sao điều này? Tôi có thể làm gì? Gần đây tôi đã cập nhật từ phiên bản 2.1.2 lên 2.1.3. Tôi cập nhật tất cả các tài liệu tham khảo và dự án đang hoạt động tốt, ngoại trừ các bài kiểm tra. Tôi cũng looked at this question, nhưng không thể như vậy, vì tôi không thay đổi các bài kiểm tra của mình, vì vậy chúng được viết tốt, nó chỉ là việc thực thi của chúng không hoạt động.

+2

Bạn nên thêm thẻ java để cho phép định dạng để kick vào và có thêm một chút về quan điểm về câu hỏi của bạn;) –

+0

đẹp tip, tôi không biết về nó, làm;) – dialex

Trả lời

14

Đó là a known issue of Play 2.1.3. Trong khi đó có a workaround. Thêm dòng sau vào tập tin Build.scala trong hàm chính val:

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

Giúp tôi một tấn .. Tôi là một newbie để chơi f/w – saurshaz