亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

功能測試中的夾具對象引用不正確

功能測試中的夾具對象引用不正確

PHP
智慧大石 2023-07-21 16:29:47
功能測試類依賴于夾具中創建的對象引用。但是,引用的 id 與實體管理器返回的對象的 id 屬性不同。下面的測試演示了這個問題。筆記:$this->setReference(...)使用 時的錯誤與使用public const ...和 時的錯誤相同$this->addReference(...)。測試中使用的對象引用似乎是非營利實體的下一個可用 ID。在更一般的測試類中觀察到錯誤后創建測試類。無論在運行測試類之前是否加載了裝置,錯誤都是相同的。該應用程序使用 Symfony 5.1.2,并更新了所有依賴項。測試類:namespace App\Tests\Controller;use Liip\TestFixturesBundle\Test\FixturesTrait;use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;class ReferenceTest extends WebTestCase{    use FixturesTrait;    public function setup(): void {        $this->client = $this->createClient();        $this->fixtures = $this->loadFixtures([                    'App\DataFixtures\Test\OptionsFixture',                    'App\DataFixtures\Test\NonprofitFixture',                    'App\DataFixtures\Test\OpportunityFixture',                    'App\DataFixtures\Test\UserFixture',                ])                ->getReferenceRepository();        $this->client->followRedirects();        $kernel = self::bootKernel();        $this->entityManager = $kernel->getContainer()                ->get('doctrine')                ->getManager('test');    }    public function testNonprofitReference() {        $npo = $this->entityManager->getRepository(\App\Entity\Nonprofit::class)                ->findOneBy(['orgname' => 'Marmot Fund']);        $nId = $npo->getId();        $id = $this->fixtures->getReference('npo')->getId();        $this->assertEquals($nId, $id, 'Reference incorrect');    }   }測試結果:Reference incorrectFailed asserting that 4 matches expected 1.
查看完整描述

1 回答

?
ABOUTYOU

TA貢獻1812條經驗 獲得超5個贊

答案是,引用在功能測試中沒有地位。它們的使用實際上是單擊鏈接或執行其他操作的快捷方式。更好的測試是使用爬蟲來模仿動作。



查看完整回答
反對 回復 2023-07-21
  • 1 回答
  • 0 關注
  • 140 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號