app服务器端api接口单元测试

公司测试人员希望能提供接口api自动化测试的功能给他们,方便他们测试和检查数据是否正确。使用了SimpleTest(http://www.simpletest.org/en/start-testing.html), 并把ostool的json(http://tool.oschina.net/codeformat/json)格式化功能整了进去,弄个自动化测试功能给他们。

单元测试用例代码例子

require_once dirname(__FILE__) . '/../component/PApi.php';
class Demo extends UnitTestCase {
	function testIplookup(){
		$url = 'http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=json&ip=218.4.255.255';
		$browser = new SimpleBrowser();
		$browser->get($url);
		PApi::showJson('手机号码归属地查询api接口'.$url, $browser->getContent());
		$this->assertEqual(200, $browser->getResponseCode());
	}
	
	function testWeather(){
		$url = 'http://www.weather.com.cn/data/cityinfo/101280101.html';
		$browser = new SimpleBrowser();
		$browser->get($url);
		PApi::showJson('广州天气接口'.$url, $browser->getContent());
		$this->assertEqual(200, $browser->getResponseCode());
	}
}

运行结果

app服务器端api接口单元测试_第1张图片

后边只需在开发时把基本接口单元测试用例写好交给测试人员就行了。

完整代码:http://git.oschina.net/penngo/PApiTest

cspeed网络测速

你可能感兴趣的:(app服务器端api接口单元测试)