After the previous architectural design, we began to write code, because the code is more involved, so will be explained several times.
Take a look at the whole structure diagram first
650) this.width=650; "src=" http://p1.pstatp.com/large/46e0000457d946e4326f "alt=" interface Automation test phpunit-Framework Code Development 1 "style=" border-style:none;margin:10px auto; "/>
Today, let's take a look at the writing in the TestCase file. Here we take the previous ancient history interface as an example.
lhl_test.php content is as follows:
<?php
Code get click Link Join QQ Group 522720170:https://jq.qq.com/?_wv=1027&k=5C08ATe
Introduce some of the necessary documents, leave it alone, and you'll talk later.
Require_once (".. /commons/require.php ");
Use Phpunitframeworktestcase;
Class Lhltest extends TestCase
{
Test cases must start with test, or phpunit do not recognize
Public Function Testlhl ()
{
Select a running environment. The host is configured in the file to read the contents of the file directly.
$RC =new readconfig ();
$url = $RC->get_host ("online");
echo $url;
Stitching the complete request string
$get _params= "date=2017-11-11&key= fill in your Application key";
$url = $url. "?". $get _params;
$content =transfer::get ($url);
Encodes the returned JSON result, which translates to objects that can be recognized by PHP for later use
$data = Json_decode ($content, true);
Print_r ($data);
if (Is_null ($data) ==false)
{
Assertion if the returned Error_code is 0 indicating that the interface succeeded
$this->assertequals (' 0 ', $data [' Error_code '], "failed");
Print ("successed");
}
}
}
?>
This article is from the "Cockroach Performance automation test brand" blog, please be sure to keep this source http://xqtesting.blog.51cto.com/4626073/1982675
Interface Automation test phpunit-Framework Code Development 1