Skip to content

Latest commit

 

History

History
59 lines (41 loc) · 1.83 KB

VDR306.md

File metadata and controls

59 lines (41 loc) · 1.83 KB

VDR306. Scenario should have only one "then" step

The Vedro framework categorizes steps into three types:

  • “given” - arrange steps, preparing data,
  • “when” - the main act,
  • “then”, “and” and “but” - asserts

The “Then” step is expected to be the only one in a scenario. Other asserts should be “and” or “but”. In that case, you can read the names of steps as one meaningful sentence.

*This rule is optional. Using several “then” steps excused for example in case there are a lot of similar assert steps all over the project

❌ Anti-pattern

class Scenario(vedro.Scenario):
    subject = "login as registered user"
    
    def given_registered_user(self):
        self.user = fake(NewUserSchema)
        registered_user(self.user)

    def when_user_logs_in(self):
        self.response = httpx.post(f"{API_URL}/auth/login", json=self.user)

    def then_it_should_return_success_response(self):
        assert self.response.status_code == 200

    def then_it_should_return_created_token(self):
        assert self.response.json() == AuthTokenSchema % {
            "username": self.user["username"]
        }

✅ Best practice

class Scenario(vedro.Scenario):
    subject = "login as registered user"
    
    def given_registered_user(self):
        self.user = fake(NewUserSchema)
        registered_user(self.user)

    def when_user_logs_in(self):
        self.response = httpx.post(f"{API_URL}/auth/login", json=self.user)

    def then_it_should_return_success_response(self):
        assert self.response.status_code == 200

    def and_it_should_return_created_token(self):
        assert self.response.json() == AuthTokenSchema % {
            "username": self.user["username"]
        }

Additional links