Laravel 8 不是 运行 新创建的测试,也没有提取已删除的测试
Laravel 8 not running newly created tests, and not picking up deleted tests
我刚刚开始使用 Laravel 8 测试套件,并选择为我的帐户创建过程创建一个功能测试。我已经 运行 php artisan make:test AccountCreation
并将第一个测试用例编写为函数,但是,当我 运行 php artisan test
它没有选择我的功能测试时,为什么?
同样,如果我尝试删除默认示例测试,我会收到一条错误消息,提示找不到该测试?我错过了什么?
tests/Feature/AccountCreation.php
<?php
namespace Tests\Feature;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;
class AccountCreation extends TestCase
{
/**
* A basic feature test example.
*
* @return void
*/
public function test_creates_user_account_successfully()
{
$response = $this->post('/api/account/create');
$response->assertStatus(201);
}
}
我是否需要 运行 的特殊命令才能 Laravel 获取这些测试?
因为你应该将 'Test' 附加到你的测试 class,因为 PHPUnit 将检查所有以 Test 结尾的 classes,所以更改:
class AccountCreation extends TestCase { ...
至:
class AccountCreationTest extends TestCase { ...
不要忘记更改您的 class 文件名。
我刚刚开始使用 Laravel 8 测试套件,并选择为我的帐户创建过程创建一个功能测试。我已经 运行 php artisan make:test AccountCreation
并将第一个测试用例编写为函数,但是,当我 运行 php artisan test
它没有选择我的功能测试时,为什么?
同样,如果我尝试删除默认示例测试,我会收到一条错误消息,提示找不到该测试?我错过了什么?
tests/Feature/AccountCreation.php
<?php
namespace Tests\Feature;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;
class AccountCreation extends TestCase
{
/**
* A basic feature test example.
*
* @return void
*/
public function test_creates_user_account_successfully()
{
$response = $this->post('/api/account/create');
$response->assertStatus(201);
}
}
我是否需要 运行 的特殊命令才能 Laravel 获取这些测试?
因为你应该将 'Test' 附加到你的测试 class,因为 PHPUnit 将检查所有以 Test 结尾的 classes,所以更改:
class AccountCreation extends TestCase { ...
至:
class AccountCreationTest extends TestCase { ...
不要忘记更改您的 class 文件名。