2 years ago

Laravel test different scenarios

Posted 2 years ago by tiagomatosweb

Hi all,

I am doing testings in Laravel 5.3+. Everything is going well, but there is a particular case that there must be a better/quicker way to create unit test.

  • Lets say I have Project model which has an attribute called status.
  • Status can be draft, in_progress and closed
  • A project belongs to a user who is the owner.
  • The owner can add other users to a project as a participant.
  • The owner only can add users while a project is in draft.

So, my ProjectTest file would have one single method for each of the scenario above? For instance:

owner_can_add_users_to_draft_project(){ ... }
owner_cant_add_users_to_inprogress_project(){ ... }
owner_cant_add_users_closed_project(){ ... }


Is that you guys usually do or is there any other better approach to avoid repetition?


Please sign in or create an account to participate in this conversation.