为phpunit中的断言块设置错误消息

为phpunit中的断言块设置错误消息,phpunit,Phpunit,有没有办法为块内的X个断言设置错误消息?我正在尝试提供更有意义的错误消息,目前我的测试代码中有一部分如下所示: $helperString = 'testInsert() @ test conflicting reasonid'; $this->assertEquals(..., ..., $helperString); $this->assertEquals(..., ..., $helperString); $this->assertEqua

有没有办法为块内的X个断言设置错误消息?我正在尝试提供更有意义的错误消息,目前我的测试代码中有一部分如下所示:

    $helperString = 'testInsert() @ test conflicting reasonid';
    $this->assertEquals(..., ..., $helperString);
    $this->assertEquals(..., ..., $helperString);
    $this->assertEquals(..., ..., $helperString);
    $this->assertEquals(..., ..., $helperString);
    $this->assertEquals(..., ..., $helperString);
    $this->assertEquals(..., ..., $helperString);
    $this->assertEquals(..., ..., $helperString);
    $this->assertEquals(..., ..., $helperString);
    $this->assertEquals(..., ..., $helperString);
这很管用,但很难看。我希望能够做到以下几点:

    $this->setMessage($helperString);
    $this->assertEquals(..., ...);
    $this->assertEquals(..., ...);
    $this->assertEquals(..., ...);
    $this->assertEquals(..., ...);
    $this->assertEquals(..., ...);
    ....

这样的功能存在吗?我不知道如何在phpunit中提供更好的输出,除了像断言1与0匹配失败之类的东西,似乎没有内置这样的功能-但您可以轻松添加自己的断言测试,例如:

$this->assertNotConflictingReasonid($x, $y);
然后在函数中,如果测试失败,则显示自定义消息。根据您的测试想要做什么以及如何做,他们还可以根据输入或比较定制消息