本文實(shí)例講述了PHPUnit 單元測試安裝與使用。分享給大家供大家參考,具體如下:
https://phpunit.de/getting-started-with-phpunit.html
官網(wǎng)提供了兩種方法安裝
1. PHP Archive (PHAR)
➜ wget -O phpunit https://phar.phpunit.de/phpunit-8.phar ➜ chmod +x phpunit ➜ ./phpunit --version PHPUnit 8.0.0 by Sebastian Bergmann and contributors.
2. Composer
➜ composer require --dev phpunit/phpunit ^8 ➜ ./vendor/bin/phpunit --version PHPUnit 8.0.0 by Sebastian Bergmann and contributors.
安裝完成后在當(dāng)前目錄下添加文件 EmailTest.php,文件內(nèi)容如下
?php declare(strict_types=1); use PHPUnit\Framework\TestCase; final class EmailTest extends TestCase { public function testCanBeCreatedFromValidEmailAddress(): void { $this->assertInstanceOf( Email::class, Email::fromString('user@example.com') ); } public function testCannotBeCreatedFromInvalidEmailAddress(): void { $this->expectException(InvalidArgumentException::class); Email::fromString('invalid'); } public function testCanBeUsedAsString(): void { $this->assertEquals( 'user@example.com', Email::fromString('user@example.com') ); } }
運(yùn)行測試
➜ ./vendor/bin/phpunit --bootstrap vendor/autoload.php tests/EmailTest PHPUnit 8.0.0 by Sebastian Bergmann and contributors. ... 3 / 3 (100%) Time: 70 ms, Memory: 10.00MB OK (3 tests, 3 assertions)
更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《PHP錯誤與異常處理方法總結(jié)》、《php字符串(string)用法總結(jié)》、《PHP數(shù)組(Array)操作技巧大全》、《PHP運(yùn)算與運(yùn)算符用法總結(jié)》、《PHP網(wǎng)絡(luò)編程技巧總結(jié)》、《PHP基本語法入門教程》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門教程》及《php優(yōu)秀開發(fā)框架總結(jié)》
希望本文所述對大家PHP程序設(shè)計(jì)有所幫助。
標(biāo)簽:隴南 唐山 通遼 武漢 南通 黃山 平頂山 河南
巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《PHPUnit 單元測試安裝與使用入門教程》,本文關(guān)鍵詞 PHPUnit,單元,測試,安裝,與,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。