Testing loging in with Behat

孤人 提交于 2019-12-25 07:09:03

问题


So I have given such scenario and feature:

Feature: User registration

  As an Unregistered User I want to be able to register to the system so that I can use it.

  Scenario: User successfully registers
    Given I am unregistered user
    When I register successfully into the system
    Then I should become a registered user
    And I should be logged on to the system

I was thinking how to write the test. What do I assert. Lets talk about I should be logged in to the system. I had done testing with phpunit and mocker before a bit.

There is not exactly told how do I validate that user is logged in. Do I have freedom to validate? Like to test if user see some div with message - "You are logged in" ? And then after writing the test - implement the feature? Also another case might be that user will be redirected to some another feature page. I do not know which one. If I would, I could write test checking is user redirected to that page.

Also the part "Given I am unregistered user" - how does it look in tests? I guess there will be some session and if tests before this test were running with logged in user, then when at this test - it also will be logged in. One thought came - to call logout link and check is response 200 every time. This will make sure that user is unregistered.

Or I guess I should discuss with business owner and ask what should happen after login.

Maybe the scenario even should be modified so that it would be visible how it will look when user is logged in? It might be that people who are writing those scenarios did not think about it and I understand its hard to think about such details. Only when you start implementing the code, the questions about details come up.

If we compare to examples from this site:

http://www.netgenlabs.com/Blog/How-to-test-with-Behat

then I clearly see from the scenarios what user does and what needs to be checked in the tests. E.g.

 Scenario: Open customer registration page
      Given I am on homepage
      When I follow "Customer registration"
      Then I should be at "/customer-registration"
      And I should see "Welcome to customer registration page!"

回答1:


The first scenario is exactly how it should look like and the second how shouldn't.

Gherkin language is not a programming language and its purpose is to cover a business example.

How you proceed an implementation of each step is only up to you and your application. The implementation also depends on the level you use for testing. If your application would change but the feature would be still the same then you should not change anything in the feature file.



来源:https://stackoverflow.com/questions/36533203/testing-loging-in-with-behat

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!