Check for 404 in codeception

1.8k views Asked by At

I use codeception with laravel. I try to write an acceptance test.

I want to check that a url exists, meaning that I don't get 404/403/etc errors. So the response should be 200.

How can I do that? Or am I wrong and I shouldn't check this in acceptance tests and instead use "I can see something" ? I'm just a little bit confused to use $I->see, because the label is likely to be changed/corrected, so relying on the label is doubtful. I just want to check that at least I dont see "not found". But depending on the 404 page design, there may not be this exactly line "not found" (what if I just put "404" in my 404 page)

1

There are 1 answers

0
Alexandru Guzinschi On

That should be a functional test, because you compare the result of an input against the specification and you don't care about something else (like intermediate results or side-effects).

Your specification says that if you visit a given page (the input), you should get a status code 200 (the result) and you can use $I->seeResponseCodeIs(200); to accomplish what you want.

Example:

$I->amOnPage('/login');
$I->seeResponseCodeIs(200);