我是3的新手,我将它与symfony2扩展一起使用,并且一切正常,但我需要在测试期间知道抛出异常的消息。假设我想开发简单的博客,所以我需要列出所有帖子,然后我写了一个功能和一个以下场景:
Feature: Browse posts
In order to browse all posts on the site
As a Visitor on the site
I need a site which shows list of all posts
Scenario: Listing all posts
Given I am on "/post"
And The database is clean
And There are following posts:
| title | content |
| Testowy tytuł posta | Testowa treść posta |
| Testowy tytuł posta numer 2 | Testowa treść posta numer 2 |
Then the response status code should be 200
Then I should see "All posts" in the "title" element
And I should see "Listing all posts"
And I should see "Testowy tytuł posta"
我实现了所需的片段并且所有测试都通过了。好的,这次我需要在url中查看带有slug的博客文章,所以我将以下场景添加到上述功能中:
Scenario: View one post by slug
Given I am on "/post/testowy-tytul-posta"
Then the response status code should be 200
Then I should see "Testowy tytuł posta" in the "title" element
And I should see "Testowa treść posta"
此时我没有实体中的slug字段,测试不应该通过并且它可以工作,但是控制台的输出如下:
Scenario: View one post by slug # src/MyVendor/BlogBundle/Features/blog/listing_posts.feature:18
Given I am on "/post/testowy-tytul-posta" # MyVendor\BlogBundle\Features\Context\FeatureContext::visit()
Then the response status code should be 200 # MyVendor\BlogBundle\Features\Context\FeatureContext::assertResponseStatus()
Current response status code is 500, but 200 expected. (Behat\Mink\Exception\ExpectationException)
Then I should see "Testowy tytuł posta" in the "title" element # MyVendor\BlogBundle\Features\Context\FeatureContext::assertElementContainsText()
And I should see "Testowa treść posta"
该行:
Current response status code is 500, but 200 expected
没有告诉我出了什么问题,当我使用-v选项运行behat命令(这会增加冗长度)时,它会给我以下输出:
Scenario: View one post by slug # src/MyVendor/BlogBundle/Features/blog/listing_posts.feature:18
Given I am on "/post/testowy-tytul-posta" # MyVendor\BlogBundle\Features\Context\FeatureContext::visit()
Then the response status code should be 200 # MyVendor\BlogBundle\Features\Context\FeatureContext::assertResponseStatus()
Current response status code is 500, but 200 expected.
+--[ HTTP/1.1 500 | http://localhost/post/testowy-tytul-posta | KernelDriver ]
|
| <body>
| <div id="content">
| <div class="header clear-fix">
| <div class="header-logo">
| <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAALYAAAA+CAMAAACxzRGDAAAAUVBMVEX////Ly8yko6WLioxkYmVXVVkwLjLl5eWxsLJKSEzy8vJxcHLY2Ni+vb89Oz9XVVh+fH+Yl5n///+xsbLY2Nlxb3KkpKWXlph+fX+LiYy+vr/IZP61AAAAAXRSTlMAQObYZgAABRBJREFUeNrVmtuWoyAQRS1FEEQSzQU7//+hYxUiXsKQZLJWM+chsUloN+WhCuguYoKyYqzmvGasKqH4HyRKxndipcgcumH8qViTM7TkUclcwaHmf5XM0eWq4km1KjdqXfMXJHVe1J3hL8lk5fCGv6wmT+o0d87U+XNrk0Y9nfv+7LM6ZJH5ZBL6LAbSxQ3Q5FDr22Skr8PQSy4n7isnsQxSX4r6pobhjCHHeDNOKrO3yGmCvZOjV9jmt8ulTdXFKdbKLNh+kOMvBzuVRa4Y7MUsdEUSWQe7xxCfZmcwjHU83LqzFvSbJQOXQvptbPnEFoyZtUUGwTeKuLuTHyT1kaP0P6cR01OKvv448gtl61dqZfmJezQmU/t+1R2fJLtBwXV6uWGwB9SZPrn0fKO2WAvQN1PUhHjTom3xgXYTkvlSKHs19OhslETq6X3HrXbjt8XbGj9b4Gi+lUAnL6XxQj8Pyk9N4Bt1xUrsLVN/3isYMug8rODMdbgOvoHs8uAb2fcANIAzkKCLYy+AXRpSU8sr1r4P67xhLgPp7vM32zlqt7Bhq2fI1Hwp+VgANxok59SsGV3oqdUL0YVDMRY7Yg8QLbVUU4NZNoOq5hJHuxEM28Sh/IyUZ8D3reR+yc...
|
Then I should see "Testowy tytuł posta" in the "title" element # MyVendor\BlogBundle\Features\Context\FeatureContext::assertElementContainsText()
And I should see "Testowa treść posta" # MyVendor\BlogB
看起来有限,并没有显示所有的响应内容。如果有一个选项只接受异常消息,那将非常有用 - 在这种情况下:
Entity 'MyVendor\BlogBundle\Entity\Post' has no field 'slug'. You can therefore not call 'findOneBySlug' on the entities' repository
并将其输出到输出而不是resposne。
答案 0 :(得分:1)
我需要做的就是在Behat \ MinkExtensio下添加behat.yml以下行:
[...]
Behat\MinkExtension:
show_auto: true
show_cmd: firefox %s
[...]
这将停止对失败步骤的测试,并打开具有给定结果的浏览器。