Skip to content

Latest commit

 

History

History
43 lines (32 loc) · 1.22 KB

VDR303.md

File metadata and controls

43 lines (32 loc) · 1.22 KB

VDR303. Scenario should have a "when" step

In Vedro framework there are 3 types of steps:

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

A scenario without the main act does not exist.

❌ Anti-pattern

class Scenario(vedro.Scenario):
    subject = "login as registered user"
    
    def given_registered_user_logined(self):
        self.user = fake(NewUserSchema)
        registered_user(self.user)
        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

✅ Best practice

class Scenario(vedro.Scenario):
    subject = "login as registered user"

    def given_user_data(self):
        self.user = fake(NewUserSchema)
    
    def given_registered_user(self):
        registered_user(self.user)

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

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

Additional links