【问题标题】:Knowing to interpret the phpunit tests知道解释 phpunit 测试
【发布时间】:2013-02-09 19:32:19
【问题描述】:

我正在尝试配置灯具,phpunit 系统返回下一条消息'.E',但我不知道如何解释它:

C:\kyopol\Apache 2.22.22\htdocs\demo\protected\tests>phpunit unit/EntityTest.php

Sebastian Bergmann 的 PHPUnit 3.7.14。

从 C:\kyopol\Apache 读取的配置 2.22.22\htdocs\demo\protected\tests\phpunit.xml

.E

时间:2 秒,内存:6.50Mb

有 1 个错误:

1) EntityTest::testRead 未定义变量:newEntity

C:\kyopol\Apache 2.22.22\htdocs\demo\protected\tests\unit\EntityTest.php:37

失败!测试:2,断言:3,错误:1。

接下来,类测试EntityTest.php数据代码:

class EntityTest extends CDbTestCase
{   
public function testCreate()
{
    //CREATE a new Entity
    $newEntity=new Entity;
    $newEntity->setAttributes(
        array(
                'name' => 'Test Entity 1',
                'description' => 'Test entity number one',
                'type_id' => 1,
                'location_lat' => 77,
                'location_lon' => 77,
                'create_time' => '2013-02-16 20:36:00',
                'create_user_id' => 1,
                'update_time' => '0000-00-00 00:00:00',
                'update_user_id' => 0,
            )
    );
    $this->assertTrue($newEntity->save(false));

    //READ a Entity
    $retrievedEntity=Entity::model()->findByPk($newEntity->id);
    $this->assertTrue($retrievedEntity instanceof Entity);
    $this->assertEquals('Test Entity 1',$retrievedEntity->name);
}

public function testRead()
    {
        //READ a Entity
        $retrievedEntity=Entity::model()->findByPk($newEntity->id);
        $this->assertTrue($retrievedEntity instanceof Entity);
        $this->assertEquals('Test Entity 1',$retrievedEntity->name);
    }
}

大写字母'E'和前一点'.'是什么意思?

一般来说:没有人说我怎么知道在 phpunit 中解释输出消息吗?

干杯。

【问题讨论】:

    标签: yii tdd phpunit database-connection fixtures


    【解决方案1】:

    您的一项测试失败了,这就是您看到 E 的原因。另一个正在通过,由 . 表示。 如果测试中有任何错误消息,它们将在最后进行总结。

    测试失败的错误消息是“未定义变量:newEntity”。

    testRead() 中的第一行是:

    $retrievedEntity=Entity::model()->findByPk($newEntity->id);
    

    但您从未在该测试中设置$newEntity

    【讨论】:

    • 完美。我们有: E: 方法错误和 .: 方法已通过。但是,你知道告诉我什么是“F”大写字母吗?赞克斯布拉姆。
    • F 失败。您没有 php 错误或异常,但您的断言失败了。
    • 我知道 I 用于不完整的测试(您通过 $this->markTestIncomplete() 使测试不完整)和 S 用于跳过的测试 ($this->markTestSkipped())。也许还有更多,搜索手册。
    • 只有我找到了这个链接,其中解释了“对于每个测试用例,当你运行它们时,phpunit命令行打印字符以显示状态。” prowareness.com/blog/unit-testing-using-phpunit-part-1
    猜你喜欢
    • 2021-02-11
    • 1970-01-01
    • 2016-06-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-29
    • 2018-02-04
    • 2015-10-05
    相关资源
    最近更新 更多