Laravel phpunit 测试在调用堆栈上找不到 TestCase 对象
P粉733166744
P粉733166744 2023-08-26 20:14:38
[PHP讨论组]
<p>在哪里运行所有测试 <code>php artisan 测试</code> 一切都按预期工作并且所有测试都运行</p> <p>现在,当我运行signle test <code>php artisan test --filter test_get_profile</code>时,我收到此有线错误</p> <pre class="brush:php;toolbar:false;">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</pre> <p>但其他一些测试仍然有效,例如 test_login 和 test_register 有效,但是当我创建新测试时,有时它有效,有时我会收到此有线错误</p> <p>PS:我添加文件路径示例 <code>php artisan test tests/Feature/AccountTest.php --filter test_get_profile</code> 我没有收到任何错误,但我不知道要始终包含文件路径</ p> <p>请<strong>注意所有测试都是空的</strong></p> <pre class="brush:php;toolbar:false;">public function test_get_profile(): void { $response = $this-&gt;get('/'); $response-&gt;assertStatus(200); }</pre> <p>有人知道这个问题吗? 我正在使用 laravel 10 和 phpunit 10</p> <p>phpunit.xml:</p> <pre class="brush:php;toolbar:false;">&lt;phpunit xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:noNamespaceSchemaLocation=&quot;./vendor/phpunit/phpunit/phpunit.xsd&quot; bootstrap=&quot;vendor/autoload.php&quot; colors=&quot;true&quot; &gt; &lt;testsuites&gt; &lt;testsuite name=&quot;Unit&quot;&gt; &lt;directory suffix=&quot;Test.php&quot;&gt;./tests/Unit&lt;/directory&gt; &lt;/testsuite&gt; &lt;testsuite name=&quot;Feature&quot;&gt; &lt;directory suffix=&quot;Test.php&quot;&gt;./tests/Feature&lt;/directory&gt; &lt;/testsuite&gt; &lt;/testsuites&gt; &lt;source&gt; &lt;include&gt; &lt;directory suffix=&quot;.php&quot;&gt;./app&lt;/directory&gt; &lt;/include&gt; &lt;/source&gt; &lt;php&gt; &lt;env name=&quot;APP_ENV&quot; value=&quot;testing&quot;/&gt; &lt;env name=&quot;BCRYPT_ROUNDS&quot; value=&quot;4&quot;/&gt; &lt;env name=&quot;CACHE_DRIVER&quot; value=&quot;array&quot;/&gt; &lt;!-- &lt;env name=&quot;DB_CONNECTION&quot; value=&quot;sqlite&quot;/&gt; --&gt; &lt;!-- &lt;env name=&quot;DB_DATABASE&quot; value=&quot;:memory:&quot;/&gt; --&gt; &lt;env name=&quot;MAIL_MAILER&quot; value=&quot;array&quot;/&gt; &lt;env name=&quot;QUEUE_CONNECTION&quot; value=&quot;sync&quot;/&gt; &lt;env name=&quot;SESSION_DRIVER&quot; value=&quot;array&quot;/&gt; &lt;env name=&quot;TELESCOPE_ENABLED&quot; value=&quot;false&quot;/&gt; &lt;/php&gt; &lt;/phpunit&gt;</pre> <p>UserTest.php</p> <pre class="brush:php;toolbar:false;">namespace Tests\Feature; use Tests\TestCase; class UserTest extends TestCase { public function test_login(): void { $response = $this-&gt;get('/'); $response-&gt;assertStatus(200); } public function test_register(): void { $response = $this-&gt;get('/'); $response-&gt;assertStatus(200); } }</pre> <p>AccountTest.php</p> <pre class="brush:php;toolbar:false;">namespace Tests\Feature; use Tests\TestCase; class AccountTest extends TestCase { /** * A basic feature test example. */ public function test_get_profile(): void { $response = $this-&gt;get('/'); $response-&gt;assertStatus(200); } }</pre></p>
P粉733166744
P粉733166744

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号