laravel框架中单元测试一个方法实现一个接口不同参数请求代码示例
Laravel  /  管理员 发布于 1星期前   157
作为测试当然是怎么方便怎么来,同一个接口不同参数请求功能编写介绍两种方式
示例代码1
class DemoTest extends TestCase
{
/**
* 测试demo
*
* @return void
*/
public function testApplyDemo()
{
$response = $this->post('/car/gas/v1/detail_v2', [
'user_id' => 5000000,
'gas_id' => 1001,
]);
$response->assertStatus(200)
->assertJsonStructure([
'ciphertext',
])
->dump();
$response = $this->post('/car/gas/v1/detail_v2', [
'xxx' => 'xxx'
]);
$response->assertStatus(200)
->assertJsonStructure([
'ciphertext',
])
->dump();
}
}
代码示例2
数据提供器方式
public function gasIds()
{
return [
[1,5000000],
[2,5000001],
];
}
/**
* @dataProvider gasIds
*/
public function testApplyDemo(int $gas_id,int $user_id)
{
$this->post('/car/gas/v1/detail_v2', [
//'user_id' => $user_id,
'gas_id' => $gas_id,
])->assertStatus(200)
->assertJsonStructure([
'ciphertext',
])
->dump();
}
数据提供器:
http://www.phpunit.cn/manual/current/zh_cn/writing-tests-for-phpunit.html#writing-tests-for-phpunit.data-providers
nkt 在
阿里云香港服务器搭建自用vpn:Shadowsocks使用流程步骤中评论 用了三分钟就被禁了,直接阿里云服务器22端口都禁了..熊丽 在
安装docker + locust + boomer压测环境实现对接口的压测中评论 试试水..博主 在
阿里云香港服务器搭建自用vpn:Shadowsocks使用流程步骤中评论 @test 也可能是国内大环境所至,也是好事,督促你该研究学习新技术..test 在
阿里云香港服务器搭建自用vpn:Shadowsocks使用流程步骤中评论 打了一次网页,然后再也打不开了。。是阿里云的缘故吗?..博主 在
centos7中Meili Search搜索引擎安装流程步骤中评论 @鹿 执行以下命令看看你的2.27版本是否存在strin..
Copyright·© 2019 侯体宗版权所有·
粤ICP备20027696号