本文实例讲述了phpunit 单元测试安装与使用。分享给大家供大家参考,具体如下:
官网提供了两种方法安装
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.
安装完成后在当前目录下添加文件 emailtest.php,文件内容如下
<?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') ); } }
运行测试
➜ ./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)
如对本文有疑问, 点击进行留言回复!!
php 使用 yansongda/pay 进行微信,支付宝支付
Codeforces Round #658 (Div. 2) (C1、C2)
van-uploader + thinkphp6.0 图片上传
网友评论