我試圖運行這個功能測試PlayFramework - 運行使用JSON渲染
public class JsonRenderTest extends FunctionalTest {
@Before
public void setup() {
Fixtures.deleteDatabase();
Fixtures.loadModels("data.yml");
}
@Test
public void testThatJsonRenderingWorks() {
Response response = GET("/recipe/1");
assertIsOk(response);
}
}
回答這個調用Action功能測試是這樣
public static void showRecipe(Long id){
Recipe recipe = Recipe.findById(id);
notFoundIfNull(recipe);
renderJSON(recipe);
}
當我使用運行在Firefox測試TestRunner at http://localhost:8080/@tests 我收到此錯誤消息:
失敗,預期響應狀態:< 200>卻被:< 404>
現在,如果我在瀏覽器中運行這個網址http://localhost:8080/recipe/1,我得到的JSON性反應我期待至極是我的食譜對象的JSON表示。
當然還有在數據庫ID爲1
配方現在,這裏是我的問題。爲什麼當瀏覽器沒有時測試失敗。我在Chrome,IE和FF中嘗試了這一結果。
任何指針將不勝感激。 感謝
-Alain
是U使用的是什麼版本的遊戲本,現在運行我的測試針對MEM數據庫的問題? 從燈具加載時,您不應該假設實體的id = 1。 嘗試做一個查找(「byName」)或其他屬性您的食譜對象,然後使用該對象ID構建URL。 – mericano1
謝謝Marco。我正在使用Play-1.2.3。我會嘗試你的建議並回報 – Alain
嘗試了你的建議,沒有區別。 – Alain