douxu3315 2014-12-01 17:27
浏览 33

在代码中检查404

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条回答 默认 最新

  • dqp99585 2014-12-05 21:00
    关注

    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);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错