首页 > Web开发 > 详细

phpUnit中assertEquals

时间:2020-03-22 23:53:27      阅读:111      评论:0      收藏:0      [点我收藏+]

assertEquals

assertEquals(mixed $expected, mixed $actual[, string $message = ‘‘])
<?php
require_once dirname(dirname(__FILE__)) . ‘\vendor\autoload.php‘;

use PHPUnit\Framework\TestCase;

class MyClassTest extends TestCase{

    /**
     * @test
     */
    public function one()
    {
        $this->assertTrue(true, ‘当条件为不为真报这条错误信息‘);
        return $one =‘one‘;
    }

    /**
     * @test
     */
    public function two()
    {
        $this->assertTrue(true, ‘当条件为不为真报这条错误信息‘);
        return $two =‘two‘;
    }

    /**
     * @test
     * @depends one
     * @depends two
     */
    public function three($one, $two)
    {
        $arr_expected_1 = [‘one‘, ‘two‘];
        $arr_expected_2 = [‘one‘];
        
        $arr_actual = [$one, $two];
        
        $this->assertEquals($arr_expected_1, $arr_actual, ‘当期望的数组和实际的数组不相等时报这条信息‘);
        $this->assertEquals($arr_expected_2, $arr_actual, ‘当期望的数组和实际的数组不相等时报这条信息‘);   
    }

}
PHPUnit 6.5.3 by Sebastian Bergmann and contributors.

Runtime:       PHP 7.2.1 with Xdebug 2.7.0

..F                                                                 3 / 3 (100%)

Time: 608 ms, Memory: 8.00MB

There was 1 failure:

1) MyClassTest::three
当期望的数组和实际的数组不相等时报这条信息
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
 Array (
     0 => ‘one‘
+    1 => ‘two‘

D:\yanjing\workspace\study_test\php\MyClass.php:39

FAILURES!
Tests: 3, Assertions: 4, Failures: 1.

phpUnit中assertEquals

原文:https://www.cnblogs.com/zxcv123/p/12548813.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!