【发布时间】:2022-01-21 02:24:41
【问题描述】:
当 PHPUnit 9.5.11 测试失败时,我正在尝试显示自定义消息(正在测试的 URL)。在我的 Symfony 4.4 应用程序中。
类很简单:
class BaseTestCase extends PantherTestCase
在我的测试中,我:
$client = static::createPantherClient();
$crawler = $client->request('GET', $url);
$this->assertSelectorExists('.some-class', $url); // <- this should display the tested $url, since the second argument is supposed to be the message to show on failure
但是当测试失败时,我得到的只是:
- App\Tests\PropertyListingTest::testListingWithFullQueryString 与 数据集 #0 ('') Facebook\WebDriver\Exception\NoSuchElementException: 没有这样的元素:无法找到元素:{“method”:“css selector","selector":".some-class"} (会话信息: 无头铬=97.0.4692.71)
这里发生了什么?如果我运行这个:
$this->assertEquals("a", "b", "!!!!TEST FAILED!!!!");
它按预期工作:
!!!!测试失败!!!!断言两个字符串相等时失败。 - - 预期的 +++ 实际 @@ @@ -'一个' +'b'
【问题讨论】:
-
你确定你的
$url不是空的$this->assertSelectorExists('.some-class', $url);吗?
标签: symfony testing phpunit symfony-panther