Rya*_*ton 9 php phpunit laravel
我刚刚开始使用 Laravel 8 测试套件,并选择为我的帐户创建过程创建功能测试。我已经运行php artisan make:test AccountCreation
并编写了第一个测试用例作为函数,但是,当我运行时php artisan test
它没有选择我的功能测试,为什么?
同样,如果我尝试删除默认示例测试,我会收到一条错误消息,告诉我找不到该测试?我缺少什么?
测试/功能/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);
}
}
Run Code Online (Sandbox Code Playgroud)
我需要为 Laravel 运行一个特殊的命令来进行这些测试吗?
Abo*_*eri 23
根据laravel doc,您应该将“Test”附加到您的测试类中,因为 PHPUnit 将检查所有以 Test 结尾的类,因此更改:
class AccountCreation extends TestCase { ...
Run Code Online (Sandbox Code Playgroud)
到:
class AccountCreationTest extends TestCase { ...
Run Code Online (Sandbox Code Playgroud)
不要忘记更改您的类文件名。
归档时间: |
|
查看次数: |
7300 次 |
最近记录: |