Usually, when we write BDD scripts, we write them from the user's point of view.
If the user is an ordinary person, they probably donβt care if the title is genuine 404. They would prefer the page to give them a clear and helpful message. Write a script to test for a clear and useful message.
Given no section on unicorns exists When the user browses for horses And changes the url to be about unicorns Then the user should be told that no such page exists.
BDD is not really about testing. It's about conversations that allow you to discover other things that you have not thought about, and develop a common understanding of what is about to happen. For example, what happens when a regular user tries to access the admin page? Do they have to be denied access or just donβt know what the page is? What if the page is deleted? These discussions are more useful than trying to attach everything.
If your 404 is associated with a specific message with the user, you can simply conduct testing to match the corresponding response. This will greatly reduce the likelihood of accidentally sending the wrong code with a message in the future, and you can focus on the real benefit.
source share