2011-07-05 14 views

回答

6

這是由設計。單元測試不應該對某些預先存在的狀態(如持久數據)有任何外部依賴關係。如果您需要數據用於測試目的,則需要在您的設置方法中設置該數據。例如:

@Before 
public void setUp() { 
    // The following loads test data from the YAML file 
    Fixtures.loadModels("test-data/users.yml"); 
} 

@Test 
public void someTest() { 
    assertEquals(5, User.count()); // 5 User records exist due to @Before method 
} 

你應該看看你的conf/application.conf文件,並注意到你有這樣一行:

%test.db=mem 

這是默認設置 - 它說,當應用程序在測試模式下運行,使用內存數據庫。如果您希望您的測試能夠處理持久數據(不推薦),則可以更改測試模式數據庫設置。有關詳細信息,請參見Play test documentation

+0

其實,真正的 '罪魁禍首' 是%test.jpa.ddl =創建 – roshan

相關問題