0
votes

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
Depends, do you want to test the UI interface for loggin in/registering, or you want to test just the logic without UI? - gvf
I guess UI. I do not mean javascript. But just user entering his data and being logged in. I talked with guy who wrote those specifications, and he says its bad to specify exact texts of buttons and fields, because if we change field, the specification also has to be changed. - Dariux

1 Answers

0
votes

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.