【问题标题】:How can I get Codeception to output array comparisons in PHPUnit format?如何让 Codeception 以 PHPUnit 格式输出数组比较?
【发布时间】:2016-11-01 05:00:12
【问题描述】:

当我使用 PHPUnit 并且由于两个数组不相等而失败时,它一次比较数组中的每个项目。但是,当我使用 Codeception(它使用 PHPUnit 进行单元测试)时,它告诉我整个数组是不同的,这不太有用。如何让 Codeception 以与 PHPUnit 相同的方式输出数组比较? Codeception 文档中似乎没有关于此的任何内容。

PHPUnit 转储:

C:\server\Apache24\htdocs\localhost\public_html\codeception_vs_phpunit>phpunit tests\BasicTest.php
PHPUnit 4.3.4 by Sebastian Bergmann.

F

Time: 141 ms, Memory: 3.75Mb

There was 1 failure:

1) BasicTest::testFoo
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
 Array (
     0 => 0
     1 => 1
     2 => 2
     3 => 3
-    4 => 4
+    4 => 42
     5 => 5
     6 => 6
     7 => 7
     8 => 8
     9 => 9
 )

C:\server\Apache24\htdocs\localhost\public_html\codeception_vs_phpunit\tests\BasicTest.php:33

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

代码接收转储:

C:\server\Apache24\htdocs\localhost\public_html\codeception_vs_phpunit>codecept run
Codeception PHP Testing Framework v2.2.1
Powered by PHPUnit 4.8.26 by Sebastian Bergmann and contributors.

Acceptance Tests (0) ---------------------------------------
------------------------------------------------------------

Functional Tests (0) ---------------------------------------
------------------------------------------------------------

Unit Tests (1) ---------------------------------------------
x BasicTest: Foo
------------------------------------------------------------


Time: 1.57 seconds, Memory: 11.00MB

There was 1 failure:

---------
1) BasicTest: Foo
 Test  tests\unit\BasicTest.php:testFoo
Failed asserting that two arrays are equal. ( -Expected | +Actual )
- Array (
-     0 => 0
-     1 => 1
-     2 => 2
-     3 => 3
-     4 => 4
-     5 => 5
-     6 => 6
-     7 => 7
-     8 => 8
-     9 => 9
- )
+ Array (
+     0 => 0
+     1 => 1
+     2 => 2
+     3 => 3
+     4 => 42
+     5 => 5
+     6 => 6
+     7 => 7
+     8 => 8
+     9 => 9
+ )

#1  C:\server\Apache24\htdocs\localhost\public_html\codeception_vs_phpunit\tests\unit\BasicTest.php:34
#2  BasicTest->testFoo
#3  C:\usr\bin\codecept.phar:7

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

【问题讨论】:

    标签: phpunit codeception


    【解决方案1】:

    升级到 Codeception 2.2.2

    https://github.com/Codeception/Codeception/blob/2.2/CHANGELOG.md#222

    • @k0pernikus 提供的更好的失败差异消息

    【讨论】:

    • 我昨晚尝试升级,但收到一条关于其中一个类未加载的大量错误消息。我没有时间调查,所以我只是恢复到 2.2.1。有时间我再试试看能不能解决错误。
    • 你能举个例子,数组差异输出在 codeception 2.2.2 中的样子吗?我在网上找不到。而在我们的项目中,这个升级很复杂,我试过一次,但是由于其他的依赖,我得到了太多的错误,看起来不可能不刹车。所以很高兴知道它是否值得。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-09
    • 2021-05-16
    • 1970-01-01
    • 1970-01-01
    • 2014-10-01
    • 1970-01-01
    相关资源
    最近更新 更多