【问题标题】:Laravel 8 not running newly created tests, and not picking up deleted testsLaravel 8 没有运行新创建的测试,也没有拾取已删除的测试
【发布时间】:2021-03-15 18:56:25
【问题描述】:

我刚刚开始使用 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 运行一个特殊的命令来获取这些测试吗?

【问题讨论】:

  • 除非另有配置,否则我相信 PHPUnit 只查找以 Test 结尾的类,因此您可能只需将 AccountCreation 更改为 AccountCreationTest。哦,相应地重命名文件。

标签: php laravel phpunit


【解决方案1】:

因为你应该将'Test'附加到你的测试类,因为PHPUnit会检查所有以Test结尾的类,所以改变:

class AccountCreation extends TestCase { ...

到:

class AccountCreationTest extends TestCase { ...

别忘了更改你的类文件名。

【讨论】:

    猜你喜欢
    • 2021-04-21
    • 2015-10-14
    • 2018-07-08
    • 1970-01-01
    • 2020-12-19
    • 2011-08-29
    • 2018-06-01
    • 2013-08-24
    • 1970-01-01
    相关资源
    最近更新 更多