Laravel 컨트롤러 테스트 작성 요령

테스트를 작성할 때 무엇을 테스트 할 것인지를 결정하는 것이 참 어려운 것 같습니다. Jeffrey Way 의 조언을 따르니 컨트롤러 테스트 작성에 꽤 도움이 되네요.

“Controller tests should verify responses, ensure that the correct database access methods are triggered, and assert that the appropriate instance variables are sent to the view.”

다음에서 발췌: JeffreyWay. ‘Laravel Testing Decoded.’ iBooks.

  1.  response 를 확인한다.
    1. $this->assertResponseIsOk() 혹은 $this->assertRedirectedTo(‘/PATH’) 등으로 확인할 수 있습니다.
  2. 원하는 모델의 메소드가 작동되었는지 확인한다.
    1. Mockery 의 shouldReceive 로 확인할 수 있습니다.
  3. 뷰에 데이터를 잘 넘겼는지 확인한다.
    1. $this->assertViewHas(‘변수명’) 으로 확인할 수 있습니다.

leaderboard-728x90

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.