Home  >  Article  >  Backend Development  >  单元测试 - php 功能测试疑问

单元测试 - php 功能测试疑问

WBOY
WBOYOriginal
2016-06-06 20:46:56913browse

原来写几个项目,使用golang(revel框架),里面写测试十分方便,比如测试一个action是否能够正常工作:

<code>func (t *UserTest) TestInfo(){
    //直接访问
    t.Get("/user/info/")
    //默认较验httpcode 是不是200
    //较验返回头是否正确
    t.AssertContentType("text/html; charset=utf-8")
    //获取返回内容
    res := string(t.ResponseBody)
    //可以对返回内容进行较验
    todo...
}
</code>

现在项目使用php yii框架,也想做这样的基本测试, 没找到类似的方法啊.
不知道各路大神php中的这些http方法平时是如何写测试的?

回复内容:

原来写几个项目,使用golang(revel框架),里面写测试十分方便,比如测试一个action是否能够正常工作:

<code>func (t *UserTest) TestInfo(){
    //直接访问
    t.Get("/user/info/")
    //默认较验httpcode 是不是200
    //较验返回头是否正确
    t.AssertContentType("text/html; charset=utf-8")
    //获取返回内容
    res := string(t.ResponseBody)
    //可以对返回内容进行较验
    todo...
}
</code>

现在项目使用php yii框架,也想做这样的基本测试, 没找到类似的方法啊.
不知道各路大神php中的这些http方法平时是如何写测试的?

一般来说php是用单元测试的话,多数都是使用phpunit测试框架来测试的

其实yii官方推荐的方案也是用phpunit(看这里)

具体怎么用的话,这里有篇教程

目前比较好的测试 还是phpunit

估计你想要的是phpunit 的selenium,但是没用过,不能给更多帮助了
https://netbeans.org/kb/docs/php/phpunit_zh_CN.html#selenium

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn