2013-10-12 31 views
0

問題我有一個問題,我的反向路由器在播放! 2.2.0玩!框架2.20-與反向路由器「參考」和功能測試

我想從我的控制器測試方法,在the documentation這樣描述:

@Test 
public void testIsSessionSpeaker_true() throws Exception { 
    // the action 
    Result result = callAction(controllers.routes.ref.UsersController.isSessionSpeaker(workshop.workshopSession.get(0)), 
           fakeRequest().withSession("uuid", "123456")); 
    // test after action 
}  

當我運行我的測試,我得到以下錯誤:

error: cannot find symbol 
Result result = callAction(controllers.routes.ref.UsersController.isSessionSpeaker(workshop.workshopSession.get(0)), 
^ 
symbol: method isSessionSpeaker(WorkshopSession) 
location: variable UsersController of type ReverseUsersController 
1 error 

的方法isSessionSpeaker我想測試一個路由是不可訪問的,所以我不能使用route(fakeRequest(PUT, "something"))和方法需要一個會話,所以我不能只是「打電話給它」像UsersController.isSessionSpeaker(...)或我得到一個There is no HTTP Context available from here.

的問題是不是從我的IntelliJ,因爲我編譯並與活化劑執行我的測試。

讀一半的網頁後,我嘗試了一些其他的方式來寫裁判爲:

controllers.WorkshopManager.routes.ref.UsersController.isSessionSpeaker(...) 
controllers.WorkshopManager.routes.UsersController.isSessionSpeaker(...) 
controllers.routes.UsersController.isSessionSpeaker(...) 
routes.ref.UsersController.isSessionSpeaker(...) 

我卡住了! 如果你想看到所有的代碼,我推它在我的git repo here

Thx提前爲您提供幫助!

回答

0

我得到答案的一個組成部分,Issue #969躲我,真正的問題(感謝Eclipse來告訴我吧!)。

反向路由器(如名稱暗示...)允許訪問方法,它有一個路線。由於isSessionSpeaker(...)是我的控制器的一種方法,它不是我的路由器的一部分,所以我不能使用callAction來測試我的方法。

現在我只需要找到一種方法來測試我控制器的方法,當你需要一個會話這是不是我的路由器的一部分,但它是一個其他問題...

+0

如果有人讀這一點,最簡單的解決辦法,我發現僞造在這種情況下會是:'公共無效fakeSession(){ Http.Context.current.set(新Http.Context(1L,模擬(RequestHeader.class),模擬(Http.Request.class ),new HashMap (), new HashMap (),new HashMap ())); Http.Context.current()。session()。put(「uuid」,UUID); }'與[文章]的幫助(http://stackoverflow.com/questions/10381354/how-to-manipulate-session-request-and-response-for-test-in-play2-0),它使用mokito,它的作品很好! –