'Should integration test bypass login natural processes in order don't retest same login functionality for many times

Let's say I'm testing a web service and I have a couple of scenarios requires user to be authenticated:

Scenario #1: Customer sign-up

Scenario #2: Customer sign-in

Scenario #3: Customer change name

Scenario #4: Customer update image

Should all the tests go through all login steps like:

1) Go to register page
2) Enter new user information
3) Activate account
4) Go to login page
5) Enter login and password
6) Press the Login button
7) Check if I authenticated as a customer

Or I can just test it once and implement endpoint which quickly creates a user and log it in.

So if I have that kind of endpoint that means I can skip retesting the same things all the time and just have short scenarios #3 and #4 implementation. But in this case, I have a less natural environment.

Please tell me about the best practices that you use in real projects.



Solution 1:[1]

Few best practices:

  • use the testing pyramid integration > ui (tests are much slower on UI, automate in the UI only the necessary things to have main flows covered)
  • for the UI use fast methods for the setup (so yes, web services, test login only once)
  • if possible keep some test data trough the builds (for example to make sure a new build that might change data structure does not affect basic functionality, e.g. login)
  • tests should be atomic (not depend on each other)
  • do some cleanup from time to time to remove duplicate test code and to improve the framework(speed, stability)

Solution 2:[2]

You shouldn't copy and paste the "log in" scenario to all of the other scenarios, but having an account and being logged in are prerequisites for the other use cases. From a behavior driven development perspective this will translate to one or more Given steps that simulate or actually perform those steps:

Scenario: Customer change name
    # Calls web service or database to create new user
    Given "Bob" is a registered user

    # Calls web service or database to make account active
    And "Bob" has an active account

    # Opens browser, navigates to login page, fills out login form and submits it
    And the user is logged in as "Bob"

    # Steps specific to changing name and asserting it has changed
    When the user changes their name to "Samuel"
    Then the user's name is "Samuel"

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Greg Burghardt
Solution 2 Greg Burghardt