Laravel phpunit 測試在呼叫堆疊上找不到 TestCase 對象
P粉733166744
P粉733166744 2023-08-26 20:14:38
0
1
600
<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->get('/'); $response->assertStatus(200); }</pre> <p>有人知道這個問題嗎?我正在使用 laravel 10 和 phpunit 10

<p>phpunit.xml:</p>

    <測試套件>
        <測試套件名稱=“單元”>
            <目錄後綴=“Test.php”>./tests/Unit
        </測試套件>
        <測試套件名稱=“功能”>
            <目錄字尾=“Test.php”>./tests/Feature
        </測試套件>
    </測試套件>
    <來源>
        <包括>
            <目錄後綴=“.php”>./app
        </含>
    </來源>
    
        <環境名稱=“APP_ENV” value="測試"/>
        
        
        
        
        
        
        
        <env name=“TELESCOPE_ENABLED”值=“假”/>
    </php>
</phpunit></pre>
<p>UserTest.php</p>
 命名空間 Tests\Feature;

使用測試\測試用例;

類別 UserTest 擴充 TestCase
{
    公共函數 test_login(): void
    {
        $response = $this->get('/');

        $響應->assertStatus(200);
    }

    公共函數 test_register(): void
    {
        $response = $this->get('/');

        $響應->assertStatus(200);
    }
}</前>
<p>AccountTest.php</p>
 命名空間 Tests\Feature;

使用測試\測試用例;

AccountTest 類別擴展了 TestCase
{
    /*** 一個基本功能測試範例。*/
    公用函數 test_get_profile(): void
    {
        $response = $this->get('/');

        $響應->assertStatus(200);
    }
}</pre></p>            
P粉733166744
P粉733166744

全部回覆(1)
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!