我正在尝试学习如何使用phpunit和laravel进行测试。 使用PostsTest.php命令开始测试时,我收到警告:
There was 1 failure:
1) Warning
No tests found in class "PostsTest".
FAILURES!
Tests: 2, Assertions: 1, Failures:
我的测试类名和文件名匹配。 我已经阅读了有关名称不匹配的其他问题。 我的文件名是PostsTest.php和我的测试文件:
class PostsTest extends ApiTester {
public function it_fetches_posts()
{
$this->times(5)->makePost();
$this->getJson('api/v1/posts');
$this->assertResponseOk();
}
private function makePost($postFields=[])
{
$post = array_merge([
'title' => $this->fake->sentence,
'content' => $this->fake->paragragraph
], $postFields);
while($this->times --)Post::create($post);
}
}
如有必要,我的ApiTester:
use Faker\Factory as Faker;
class ApiTester extends TestCase {
protected $fake;
protected $times = 1;
function __construct($faker)
{
$this->fake = Faker::create();
}
}
我不知道错误在哪里。 Laravel或本地phpunit设置或其他任何设置。 任何帮助表示赞赏。
谢谢。