【发布时间】:2021-12-15 02:20:04
【问题描述】:
我的 Laravel 项目中有这个测试:
// here are some test function configurations
// found nothing if not match
$this->post(action([TagController::class, 'search'], '!! Not foundable name !!'))
->assertOk()
->assertJsonCount(0, 'data');
// found it if match
$this->post(action([TagController::class, 'search'], $matchName))
->assertOk()
->assertJsonCount(1, 'data');
// found it if partly match
$this->post(action([TagController::class, 'search'], $partlyMatchName))
->assertOk()
->assertJsonCount(1, 'data');
现在如果测试失败,我会看到这个结果:
Failed to assert that the response count matched the expected 0
Failed asserting that actual size 4 matches expected size 0.
这对我来说并不过分,我不知道哪个断言失败以及确切原因。我想为这种情况定义自定义消息。
我想做这样的事情:
->assertJsonCount(
0,
'data',
'It should found noting, because of conditions are not match'
);
在这种情况下,有没有办法向测试用户发送自定义消息?
【问题讨论】: