【发布时间】:2023-02-24 02:26:58
【问题描述】:
我创建了以下单元测试:
<?php
namespace Tests\Unit;
use PHPUnit\Framework\TestCase;
class DistrictKindTest extends TestCase
{
/**
* Index method unit test.
*
* @return void
*/
public function test_index()
{
$response = $this->json('GET', '/api/distinct-kinds');
$response->assertStatus(200);
}
}
然后我运行命令:vendor/bin/phpunit --coverage-html tests/coverage 我得到以下错误:
PHPUnit 9.6.3 by Sebastian Bergmann and contributors.
E.... 5 / 5 (100%)
Time: 00:00.151, Memory: 20.00 MB
There was 1 error:
1) Tests\Unit\DistrictKindTest::test_index
Error: Call to undefined method Tests\Unit\DistrictKindTest::json()
/var/www/html/tests/Unit/DistrictKindTest.php:23
ERRORS!
Tests: 5, Assertions: 13, Errors: 1.
我应该用什么来修复这个错误? 也许我必须添加一些类的使用来修复这个错误? 你能建议我如何解决它吗?
【问题讨论】:
标签: laravel api rest testing phpunit