【发布时间】:2022-09-23 18:55:00
【问题描述】:
我是 laravel 单元测试的新手,目前在我的测试中遇到错误。请在下面查看我的代码。
测试
/** @test */
public function users_can_view_homepage_products()
{
$response = $this->get(\'api/products\');
$response->assertStatus(200)
->assertJson([
\'id\' => 1,
\'name\' => ucwords($this->faker->words(3, true)),
\'slug\' => ucfirst($this->faker->slug),
\'intro\' => $this->faker->sentence,
\'price\' => number_format($this->faker->randomFloat(2, 100, 99999), 2)
]);
}
控制器
public function index()
{
return [
\'id\' => 1,
\'name\' => \'Airpods Pro (2021)\',
\'slug\' => \'airpods-pro-2021\',
\'intro\' => \'New and powerful airpods from apple.\',
\'price\' => 12400
];
}
错误
-
测试用例失败,价格与测试场景不匹配请添加并仅尝试价格中的整数值
标签: laravel unit-testing