我通过CakePHP v2.3使用PHPUnit 3.7.10并运行以下命令:
$this->assertEquals(array('a', 'b', 'c'), array('a', 'c', 'd'));
我得到的只是:
Failed asserting that two arrays are equal.
为什么我没有得到如下所述的差异? http://www.phpunit.de/manual/current/en/writing-tests-for-phpunit.html#writing-tests-for-phpunit.assertions.assertEquals.example5
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
Array (
0 => 'a'
- 1 => 'b'
- 2 => 'c'
+ 1 => 'c'
+ 2 => 'd'
)
我错过了什么?
更新即可。通过test.php调用的测试文件?case = Cache / Engine / PhpUnit& debug = 1
<?php
class PhpUnitTest extends CakeTestCase {
public function testDiff() {
$this->assertEquals(array('a', 'b', 'c'), array('a', 'c', 'd'));
}
}
答案 0 :(得分:0)
适合我:
<?php
class SoTest extends PHPUnit_Framework_TestCase
{
public function testIt()
{
$this->assertEquals(array('a', 'b', 'c'), array('a', 'c', 'd'));
}
}
?>
输出:
$ phpunit SoTest.php
PHPUnit 3.7.10 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 3.00Mb
There was 1 failure:
1) SoTest::testIt
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
Array (
0 => 'a'
- 1 => 'b'
- 2 => 'c'
+ 1 => 'c'
+ 2 => 'd'
)
/home/cweiske/SoTest.php:6
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
答案 1 :(得分:0)
您正在浏览器上运行单元测试。使用--debug
修饰符在CLI上运行时,您将看到预期的结果。您还可以尝试在使用网络浏览器运行测试时在网址末尾添加&debug=1
,但这对我来说没有多次工作。
答案 2 :(得分:0)