小编d3r*_*idi的帖子

Laravel phpunit 测试在调用堆栈上找不到 TestCase 对象

运行所有测试 php artisan test 一切都按预期运行并且所有测试都运行

在此输入图像描述

现在,当我运行单一测试时,php artisan test --filter test_get_profile我收到此有线错误

An error occurred inside PHPUnit.

Message:  Cannot find TestCase object on call stack
Location: D:\laragon\www\project\vendor\phpunit\phpunit\src\TextUI\TestRunner.php:68
Run Code Online (Sandbox Code Playgroud)

但其他一些测试仍然有效,例如 test_login 和 test_register 有效,但是当我创建新测试时,有时它有效,有时我会收到此有线错误

PS:我添加了文件路径示例,php artisan test tests/Feature/AccountTest.php --filter test_get_profile我没有收到任何错误,但我不知道要始终包含文件路径

注意,所有测试都是空的

public function test_get_profile(): void
    {
        $response = $this->get('/');

        $response->assertStatus(200);
    }
Run Code Online (Sandbox Code Playgroud)

有人知道这个问题吗?我正在使用 laravel 10 和 phpunit 10

phpunit.xml:

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
         bootstrap="vendor/autoload.php"
         colors="true"
>
    <testsuites>
        <testsuite name="Unit">
            <directory suffix="Test.php">./tests/Unit</directory>
        </testsuite>
        <testsuite name="Feature">
            <directory suffix="Test.php">./tests/Feature</directory>
        </testsuite>
    </testsuites>
    <source>
        <include>
            <directory …
Run Code Online (Sandbox Code Playgroud)

php phpunit laravel laravel-testing

5
推荐指数
1
解决办法
1700
查看次数

标签 统计

laravel ×1

laravel-testing ×1

php ×1

phpunit ×1