Skip to content

Latest commit

 

History

History
52 lines (38 loc) · 1.46 KB

VDR300.md

File metadata and controls

52 lines (38 loc) · 1.46 KB

VDR300. Step name should start with..

The Vedro framework categorizes steps into three types:

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

In order to ease scenario reading all names of steps should start with their type.

❌ Anti-pattern

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

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

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

    def created_token_in_response(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 = registered_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