您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
phpunit断言-assertGreaterThanOrEqual
发布时间:2021-10-02 22:59:06编辑:雪饮阅读()
assertGreaterThanOrEqual断言用来断言一个实际值是否大于或等于预期值,若实际值大于或等于预期值,则断言为真,否则断言为假。
GreatThanOrEqualTest.php:
<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
final class GreatThanOrEqualTest extends TestCase
{
public function testFailure(): void
{
$this->assertGreaterThanOrEqual(2, 1);
}
public function testTwo(): void
{
$this->assertGreaterThanOrEqual(2, 2);
}
public function testSuccess(): void
{
$this->assertGreaterThanOrEqual(2, 3);
}
}
use PHPUnit\Framework\TestCase;
final class GreatThanOrEqualTest extends TestCase
{
public function testFailure(): void
{
$this->assertGreaterThanOrEqual(2, 1);
}
public function testTwo(): void
{
$this->assertGreaterThanOrEqual(2, 2);
}
public function testSuccess(): void
{
$this->assertGreaterThanOrEqual(2, 3);
}
}
运行结果:
C:\Users\Administrator>D:\phpstudy_pro\Extensions\php\php7.4.3nts\php.exe C:\Users\Administrator\PhpstormProjects\untitled\vendor\phpunit\phpunit\phpunit -c C:\Users\Administrator\PhpstormProjects\untitled\organizing\phpunit.xml C:\Users\Administrator\PhpstormProjects\untitled\organizing\tests\GreatThanOrEqualTest.php
PHPUnit 9.5.8 by Sebastian Bergmann and contributors.
F.. 3 / 3 (100%)
Time: 00:00.009, Memory: 6.00 MB
There was 1 failure:
1) GreatThanOrEqualTest::testFailure
Failed asserting that 1 is equal to 2 or is greater than 2.
C:\Users\Administrator\PhpstormProjects\untitled\organizing\tests\GreatThanOrEqualTest.php:7
FAILURES!
Tests: 3, Assertions: 6, Failures: 1.
关键字词:phpunit,assertGreaterThanOrEqual