在哪里运行所有测试
php artisan 测试
一切都按预期工作并且所有测试都运行
现在,当我运行signle 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
但其他一些测试仍然有效,例如 test_login 和 test_register 有效,但是当我创建新测试时,有时它有效,有时我会收到此有线错误
PS:我添加文件路径示例 php artisan test tests/Feature/AccountTest.php --filter test_get_profile 我没有收到任何错误,但我不知道要始终包含文件路径 p>
请注意所有测试都是空的
public function test_get_profile(): void
{
$response = $this->get('/');
$response->assertStatus(200);
}
有人知道这个问题吗? 我正在使用 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 suffix=".php">./app</directory>
</include>
</source>
<php>
<env name="APP_ENV" value="testing"/>
<env name="BCRYPT_ROUNDS" value="4"/>
<env name="CACHE_DRIVER" value="array"/>
<!-- <env name="DB_CONNECTION" value="sqlite"/> -->
<!-- <env name="DB_DATABASE" value=":memory:"/> -->
<env name="MAIL_MAILER" value="array"/>
<env name="QUEUE_CONNECTION" value="sync"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="TELESCOPE_ENABLED" value="false"/>
</php>
</phpunit>
UserTest.php
namespace Tests\Feature;
use Tests\TestCase;
class UserTest extends TestCase
{
public function test_login(): void
{
$response = $this->get('/');
$response->assertStatus(200);
}
public function test_register(): void
{
$response = $this->get('/');
$response->assertStatus(200);
}
}
AccountTest.php
namespace Tests\Feature;
use Tests\TestCase;
class AccountTest extends TestCase
{
/**
* A basic feature test example.
*/
public function test_get_profile(): void
{
$response = $this->get('/');
$response->assertStatus(200);
}
} Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号