您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
phpunit断言-assertGreaterThan
发布时间:2021-10-02 22:32:34编辑:雪饮阅读()
assertGreaterThan断言用于断言一个实际值大于预期值才算断言成功
GreaterThanTest.php:
<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
final class GreaterThanTest extends TestCase
{
public function testFailure(): void
{
$this->assertGreaterThan(2, 1);
}
public function testSuccess(): void
{
$this->assertGreaterThan(2, 2);
}
public function testThree(): void
{
$this->assertGreaterThan(2, 3);
}
}
use PHPUnit\Framework\TestCase;
final class GreaterThanTest extends TestCase
{
public function testFailure(): void
{
$this->assertGreaterThan(2, 1);
}
public function testSuccess(): void
{
$this->assertGreaterThan(2, 2);
}
public function testThree(): void
{
$this->assertGreaterThan(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\GreaterThanTest.php
PHPUnit 9.5.8 by Sebastian Bergmann and contributors.
FF. 3 / 3 (100%)
Time: 00:00.009, Memory: 4.00 MB
There were 2 failures:
1) GreaterThanTest::testFailure
Failed asserting that 1 is greater than 2.
C:\Users\Administrator\PhpstormProjects\untitled\organizing\tests\GreaterThanTest.php:8
2) GreaterThanTest::testSuccess
Failed asserting that 2 is greater than 2.
C:\Users\Administrator\PhpstormProjects\untitled\organizing\tests\GreaterThanTest.php:12
FAILURES!
Tests: 3, Assertions: 3, Failures: 2.
关键字词:phpunit,assertGreaterThan