This is an excerpt of my upcoming ebook Laravel Testing 101. If you haven’t read the previous chapter yet (available for free here: Adding Tests to your Laravel CRUD Application: Where to Start?), please do so before reading this one.
Now that you understand that you should be looking at tests from a different angle, and that we should test mainly controllers, you might start to ask, “… but what should I be testing exactly?”
In this chapter, we are going to answer this question and describe what we will be testing in the rest of the ebook.
But first, let’s get the demo application the book is built upon up and running.
Clone the following repo
and run the application after you follow all the steps in the
After you fire up your server/application, you should get this front page:
So far, here is what you can do within the application:
/new-article) and you’ll get redirected to the signup page (since adding a new article requires signing up).
/articles/15), or user names (
/users/5) to view the articles or their authors profiles.
After signing up you’d be able to view the
/new-article route (which was redirecting to the sign up page when we tried it earlier without signing in)
After saving your article, you can view it, and since it is your own article, you would see the “edit article” button at the end of the page (you won’t see it on articles that you do not own).
When clicking on this button, you get the edit form of the article, where you can edit and save the article or you could delete it.
When updating the article you’ll get redirected to it again, with a success message.
But if you delete it, you’ll get redirected to the “all articles” page with a different success message.
You won’t see an “edit” button if you visit articles that you didn’t create yourself, but if you try to access the edit page of an article you don’t own via the URL directly (ex:
articles/16/edit), you’ll get a 403 page.
Let’s go back to the “Write a new article” page and try to add a new article with a short title and/or a short body (shorter than 10 characters).
You’ll get an error message. And the same thing happens when editing.
So even though the application is small, there are multiple things we need to test to ensure that the application is working as expected.
And here is the list:
So if we manage to automate testing the above list, we could be assured that each time we add a new feature or change a code, the application will keep working as expected.
In the next chapter, we will start writing tests with functionalities related to guests users.
If you want to follow along, and get notified of any progress with this ebook (new free chapters for instance), please sign up here: https://laraveltesting101.com/